Php floating-point rounding function This article introduces two common functions round rounding in php at the same time ceil function, which may retain digits in decimal places.
The round () function rounds a floating point number.
Syntax: float round (float val [, int precision])
Return the result of rounding val by the specified precision (number of digits after decimal point). The default value of precision can also be negative or zero ).
The code for round () is as follows:
Echo round (3.4); // 3
Echo round (3.5); // 4
Echo round (3.6); // 4
Echo round (3.6, 0); // 4
Echo round (1.95583, 2); // 1.96
// Open-source software: phpfensi.com
Echo round (1241757,-3); // 1242000
Echo round (5.045, 2); // 5.05
Echo round (5.055, 2); // 5.06
?>
Ceil -- integer in a single method
Description: float ceil (float value)
Return the next integer of no less than value. if the value has a decimal part, the type returned by ceil () is still float, because the float value range is usually larger than integer.
Example 1. ceil (): The code is as follows:
Echo ceil (4.3); // 5
Echo ceil (9.999); // 10
?>