开发者

Simple question on how to format a number

my question is the following and I guess is really simple. I have a number echoed with PHP. For ex开发者_JAVA百科ample 37452. I would like to have a dot and be displayed like 37.452

My var is $numposts

How is this possible ? Thank you


Take a look at number_format. The signature is:

string number_format ( 
    float $number , int $decimals = 0 , 
    string $dec_point = '.' , string $thousands_sep = ',' 
)

Example:

<?php

echo number_format(37452) . "\n";
// 37,452

echo number_format(37452, 0, ',', '.') . "\n";
// 37.452

?>


use number_format with custom decimal and thousands characters.

number_format(37452, 0, ',', '.');


As The MYYN correctly mentions, you should check out the number_format function:

In your example, you could use it as such:

echo number_format($numposts, 3, ',', '.');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜