The PHP rounding functions we often use are mainly: ceil, floor, round, intval.
ceil -- further rounding
Explanation
float ceil ( float value )
Returns the next integer that is not less than value. If value has a decimal part, it is rounded up by one. The type returned by ceil() is still float because the range of float values is usually larger than that of integer.
PHP rounding function example 1. ceil() example
Copy code The code is as follows:
< ?php echo ceil(4.3);
// 5 echo ceil(9.999);
// 10
?>
floor -- Rounding by rounding method
Explanation
float floor ( float value )
Returns the next integer not greater than value, and rounds the decimal part of value. The type returned by floor() is still float because the range of float values is usually larger than that of integer.
PHP rounding function example 1. floor() example
Copy code The code is as follows:
< ?
php echo floor(4.3);
// 4 echo floor(9.999);
// 9
?>
round -- Round floating point numbers
Instructions
Copy code The code is as follows:
float round ( float val [, int precision] )
Returns the result of rounding val according to the specified precision (the number of decimal digits after the decimal point). precision can also be negative or zero (the default).
PHP rounding function example 1. round() example
Copy code The code is as follows:
< ?
php 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 echo round(1241757, -3);
// 1242000 echo round(5.045, 2);
/ / 5.05 echo round(5.055, 2);
// 5.06
?>
intval---Convert the variable to integer type
PHP rounding function example intval()
Copy code The code is as follows:
< ?
php echo intval(4.3);
//4 echo intval(4.6);
//4
?>
http://www.bkjia.com/PHPjc/313675.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313675.htmlTechArticleThe PHP rounding functions we often use are mainly: ceil, floor, round, intval. ceil -- rounding to the nearest integer Description float ceil (float value) returns the next integer that is not less than value...