开发者

How to check how many characters in variable, and add space between characters in that var?

I have a 'price' variable that contains some integer number fro开发者_如何学运维m a MySQL database.

I want to check how many numbers the 'price' variable contains, and add a space in the variable depending on how many numbers. See below:

Example:

If 'price' is 150000 I would like the output to be 150 000 (notice the space). OR, if it is 19000 I would like it to output 19 000...

How would you do this the easiest way?


The easiest way is to use number_format():

$str = number_format($number, 0, '.', ' ');


Use the number_format function to format a number:

number_format($number, 0, '.', ' ')


If what you are trying to do is format the number with grouped thousands and a space as the thousand separator, use this.

number_format($number, 2, '.', ' ');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜