How to add .00 in any value using PHP?
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()
精彩评论