php method to retain two decimal places without rounding: use the function substr, the code is [echo sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2))】.
php method of retaining two decimal places and not rounding:
php retaining two decimal places and not rounding
The code is as follows:
$num = 123213.666666; echo sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2));
php rounding to an integer
The code is as follows:
echo ceil(4.3); // 5 echo ceil(9.999); // 10
php rounding to an integer
The code is as follows:
echo floor(4.3); // 4 echo floor(9.999); // 9
If you want to learn more about programming, please pay attention to the php training column!
The above is the detailed content of How to retain two decimal places in php without rounding. For more information, please follow other related articles on the PHP Chinese website!