2 decimal numbers in php?
For example:
(a)123 / (b)1000开发者_如何学C = (c)0,123 echo c must be 0,12 How can this be done ?Use round()
, sprintf()
or number_format()
.
Examples:
<?php
$res = 123/1000;
printf('%.2f', $res);
echo round($res, 2);
echo number_format($res, 2);
?>
Use number_format
http://php.net/number_format
Using sprintf() can be a way to do that.
精彩评论