Home >Backend Development >PHP Tutorial >3 ways to convert decimals to integers in PHP_PHP Tutorial

3 ways to convert decimals to integers in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:151032browse

float floor ( float value) rounding by rounding

Returns the next integer not greater than value, and rounds the decimal part of value. The type returned by floor() is still float because the range of float values ​​is usually larger than that of integer.

Copy code The code is as follows:
echo floor(4.3); // 4
echo floor(9.999); // 9

float ceil ( float value) Rounding to the nearest integer

Returns the next integer that is not less than value. If value has a decimal part, it is rounded up by one digit. The type returned by ceil() is still float because the range of float values ​​is usually larger than that of integer.

Copy code The code is as follows:

echo ceil(4.3); // 5
echo ceil(9.999); // 10

float round ( float val [, int precision]) Round floating point numbers

Returns val rounded to the specified precision (the number of decimal digits after the decimal point). precision can also be negative or zero (default).

Copy code The code is as follows:

echo round(3.4);             // 3
echo round(3.5);              // 4
echo round(3.6);              // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.04
echo round(5.055, 2); // 5.06

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824751.htmlTechArticlefloat floor (float value) The rounding method returns the next integer not greater than value, and the decimal of value Round off parts. The type returned by floor() is still float, because float values...
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