How does php keep the number 2 decimal places and not round it up
This article mainly explains "how php retains 2 decimal places and does not round off". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how php retains 2 decimal places and does not round off" together!
Operating environment: Windows 7 system, PHP 7.1 version, DELL G3 computer
How does php retain 2 decimal places and not round?
PHP Rounding and Unrounding to Two Decimals
php to two decimal places and rounding
$num = 123213.666666; echo sprintf("%.2f", $num);
php keeps two decimal places and does not round off
$num = 123213.666666; echo sprintf("%.2f",substr(sprintf("%.3f", $num), 0, -2));
Php is rounded off.
echo ceil(4.3); // 5 echo ceil(9.999); // 10
php rounding off method, take integer
echo floor(4.3); // 4 echo floor(9.999); // 9 Thank you for reading, the above is "php how to retain 2 decimal places and not rounding" content, after the study of this article, I believe we have a deeper understanding of how php retains 2 decimal places and does not round this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!