Four commonly used methods for taking integer functions in PHP:
1. Round directly, discard decimals, and keep integers: intval();
2. Rounding: round();
3. Round up and add 1 if there are decimals: ceil();
4. Round down: floor().
1. intval—convert variables into integer types
If intval is a character type, it will be automatically converted to 0.
intval(3.14159); // 3
intval(3.64159); // 3
intval('ruesin'); //02. Rounding: round()
Rounds parameter 1 to the precision specified by parameter 2. Parameter 2 can be negative or zero (default).
round(3.14159); // 3
round(3.64159); // 4
round(3.64159, 0); // 4
round(3.64159, 2); // 3.64
round(5.64159, 3); // 3.642
round(364159, -2); // 3642003. Round up and add 1 if there are decimals: ceil()
Returns the next integer that is not less than value. If value has a decimal part, it is rounded up.
This method is often used when we write paging classes to calculate the number of pages.
ceil(3.14159); // 4
ceil(3.64159); // 44. Round down: floor()
Returns the next integer not greater than value, with the decimal part of value rounded off.
floor(3.14159); // 3
floor(3.64159); // 3