Home >Backend Development >PHP Problem >How to convert decimal to integer in php
How to convert php into integers: 1. Use the ceil function to perform further operations on decimal values; 2. Use the floor function to convert float type decimals into float values without decimal points; 3. Use the rounding method , if the decimal point exceeds 5, then round it to one, otherwise it can be rounded off.
php converts decimals into integers
The first method is to use the ceil function to convert decimal values A further operation is to add one to the integer part of whatever is after the decimal point
As shown in the figure, both values are relative to the integer part plus one
The second method is to use the floor function to convert the float type decimal into a float value without a decimal point
You can see it after running Out, that is, 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 Same
The last method is what we often call the rounding method. After the decimal point, every 5 is rounded to one, otherwise it is rounded off
Then the running result is as shown in the figure, 3.333 is rounded off and becomes 3, 8.888 becomes 9,
For a lot of related knowledge, please visit PHP Chinese website !
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!