PHP Digit rounding functions

Yepkoo

Yepkoo
Staff member
PHP:
// The ceil function rounds fractions up
echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3

// floor function rounds fractions down
echo floor(4.3);   // 4
echo floor(9.999); // 9
echo floor(-3.14); // -4

// The round function rounds the fraction to the upper digit if it is 5 or higher, and to the lower digit if it is lower.
echo round(4.3);   // 4
echo round(4.6);   // 5
echo round(9.2);   // 9
echo round(9.5);   // 10
echo round(-3.14); // -3
echo round(-3.6);  // -4
echo round(7.19985,2); // 7.2
 
Top