Home > Article > Backend Development > How to convert decimal to integer in php
PHP method to convert decimals to integers: 1. Use the ceil function, with syntax such as "ceil($f1)"; 2. Use the floor function, with syntax such as "floor($f1)"; 3. Pass round function, the syntax is "round($f1)".
Recommendation: "PHP Video Tutorial"
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.
PHP method for converting decimals into integers:
The first method is to use the ceil function to perform further operations on decimal values , that is, no matter what is after the decimal point, add one to the integer part
As shown in the figure, both values increase one to the integer part
The second method is to use the floor function to convert the float type decimal into a float value without a decimal point
After running, it can be seen that The value after the decimal point is discarded
This method directly obtains the integer value part of the decimal type, regardless of what is after the decimal point, the result is the same as the second method
The last method is what we often call the rounding method. After the decimal point, 5 is rounded to one, otherwise it is discarded.
Then run The result is as shown in the figure, 3.333 is rounded off and becomes 3, 8.888 becomes 9,
The above is the detailed content of How to convert decimal to integer in php. For more information, please follow other related articles on the PHP Chinese website!