Home >Backend Development >PHP Tutorial >Summary of methods and examples of taking integers in PHP
In addition, I will introduce to you the four commonly used methods of taking integers in PHP. Four functions are mainly used: ceil, floor, round, intval. 1, ceil — rounding to the next round illustrate floatceil(floatvalue) Returns the next integer that is not less than value. If value has a decimal part, it is rounded up. The type returned by ceil() is still float because the range of float values is usually larger than that of integer. example:
2, floor — rounding method all illustrate float floor (float value) Returns the next integer not greater than value, with the decimal part of value rounded off. The type returned by floor() is still float because the range of float values is usually larger than that of integer. example:
3, round — perform a floating point number rounding illustrate 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). example:
4, intval — Convert variables to integer type example:
|