PHP Three Methods of Converting Decimal to Integer

  • 2021-07-06 10:33:38
  • OfStack

float floor (float value) rounding

Returns the next integer not greater than value, rounding off 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.

echo floor(4.3);   // 4 
echo floor(9.999); // 9

float ceil (float value) rounding by one method

Returns the next integer not less than value, and value is entered by one digit if there is a decimal part. The type returned by ceil () is still float, because the range of float values is usually larger than that of integer.


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

float round (float val [, int precision]) round up floating-point numbers by 4 and enter by 5

Returns the result of rounding val by 4 to 5 according to the specified precision precision (the number of digits after the decimal point). precision can also be negative or zero (default).


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


Related articles: