Home > Article > Backend Development > PHP floating point number rounding function_PHP tutorial
This article introduces two commonly used functions for rounding floating point numbers in PHP: round and the ceil function, which may retain the number of decimal places.
The round() function rounds floating point numbers
Grammar
float round ( float val [, int precision] )
Returns val rounded to the specified precision (the number of decimal digits after the decimal point). precision can also be negative or zero (default).
round() example
The code is as follows | Copy code | ||||||||
echo round(3.5); // 4 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06
|
Description
http://www.bkjia.com/PHPjc/445302.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445302.htmlTechArticleThis article introduces two commonly used functions for rounding floating point numbers in php, round and the ceil function, which may Number of decimal places to keep. The round() function rounds floating point numbers. Syntax...