Home >Backend Development >PHP Problem >How to convert decimal to integer in php

How to convert decimal to integer in php

藏色散人
藏色散人Original
2020-07-06 09:43:113272browse

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.

How to convert decimal to integer in php

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

How to convert decimal to integer in php

As shown in the figure, both values ​​are relative to the integer part plus one

How to convert decimal to integer in php

The second method is to use the floor function to convert the float type decimal into a float value without a decimal point

How to convert decimal to integer in php

You can see it after running Out, that is, the value after the decimal point is discarded

How to convert decimal to integer in php

# 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

How to convert decimal to integer in php

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

How to convert decimal to integer in php

Then the running result is as shown in the figure, 3.333 is rounded off and becomes 3, 8.888 becomes 9,

How to convert decimal to integer in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn