Home  >  Article  >  Backend Development  >  How many ways to convert decimal to integer in PHP?

How many ways to convert decimal to integer in PHP?

烟雨青岚
烟雨青岚Original
2020-06-15 09:53:283007browse

How many ways to convert decimal to integer in PHP?

#What are the ways to convert decimals to integers in php?

Methods for converting decimals to integers:

The first method:

Use the ceil function, for small The further operation on the numerical value is to add one to the integer part no matter what it is after the decimal point.

How many ways to convert decimal to integer in PHP?

The result of the operation: Both values ​​are added relative to the integer part One

How many ways to convert decimal to integer in PHP?

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

How many ways to convert decimal to integer in PHP?

After running, it can be seen that the value after the decimal point is discarded

How many ways to convert decimal to integer in PHP?

This method is to directly obtain the decimal The integer value part of the type, regardless of what is after the decimal point, The operation result is the same as the second method

How many ways to convert decimal to integer in PHP?

The third Method: is the rounding method we often talk about. After the decimal point, 5 is rounded up, otherwise it is rounded off.

How many ways to convert decimal to integer in PHP?

The result of the operation: 3.333 is rounded off to become 3, and 8.888 is rounded off. Became 9,

How many ways to convert decimal to integer in PHP?

Recommended tutorial: "php tutorial"

The above is the detailed content of How many ways 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