开发者

How to add .00 in any value using PHP?

开发者 https://www.devze.com 2023-02-28 21:16 出处:网络
I want to add .00 to my value. For exam开发者_运维百科ple: 100 will be 100.00 100.26 will be 100.26 only.

I want to add .00 to my value.

For exam开发者_运维百科ple:

100 will be 100.00

100.26 will be 100.26 only.


$YOUR_VALUE = 1000.25;
echo number_format($YOUR_VALUE, 2); 


number_format() can be your friend


Like @Gaurav said, use the number_format() function. Simply pass it the value and the number of digits you want there to be after the decimal point:

$value = 100;
echo number_format($value, 2); //prints "100.00"

Note that by default, it will also insert commas as the thousands separator:

$value = 2013;
echo number_format($value, 2); //prints "2,013.00"

You can change the characters that are used as the decimal point and thousands separator by passing them in as the third and fourth parameters to the function:

$value = 2013;
echo number_format($value, 2, ',', ' '); //prints "2 013,00"


number_format(100, 2, '.', ' ')


you can use

round()

or

number_format()

0

精彩评论

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