Home  >  Article  >  Backend Development  >  How to convert decimal to integer in php

How to convert decimal to integer in php

藏色散人
藏色散人Original
2020-11-23 09:59:373216browse

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)".

How to convert decimal to integer in php

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

How to convert decimal to integer in php

As shown in the figure, both values ​​​​increase one to the integer part

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

After running, it can be seen that 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

How to convert decimal to integer in php

The last method is what we often call the rounding method. After the decimal point, 5 is rounded to one, otherwise it is discarded.

How to convert decimal to integer in php

Then run The 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

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