开发者

Make dots between numbers in php

I would like to make dots bet开发者_高级运维ween my total value.

If i have 425000 i would like it to show as 425.000

Is there a function in php that implodes dots for numbers or how can i do this then?


Use number_format for this:

$number =  425000;
echo number_format( $number, 0, '', '.' );

The above example means: format the number, using 0 decimal places, an empty string as the decimal point (as we're not using decimal places anyway), and use . as the thousands separator.

Unless of course I misunderstood your intent, and you want to format the number as a number with 3 decimal places:

$number =  425000;
echo number_format( $number, 3, '.', '' );

The above example means: format the number, using 3 decimal places, . as the decimal point (default), and an empty string as the thousands separator (defaults to ,).

If the default thousands separator is good enough for you, you can just use 1:

$number =  425000;
echo number_format( $number, 3 );


1) Mind you: number_format accepts either 1, 2 or 4 parameters, not 3.


I guess you're looking for the number_format function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜