SoFunction
Updated on 2025-03-10

Simple operation example of php numerical calculation num class

This article describes the simple operation of php numerical calculation of num class. Share it for your reference, as follows:

ceil(float $value);//Return the next integer not less than value. If there is a decimal part, it will be added to one

<?php
echo ceil(4.3);  // 5
echo ceil(9.999); // 10
echo ceil(-3.14); // -3
?> 

floor(float $value);//Return the closest integer not greater than value, and round the decimal part away.

<?php
echo floor(4.3);  // 4
echo floor(9.999); // 9
echo floor(-3.14); // -4
?> 

round(float $val,[int $pre], [$mode = PHP_ROUND_HALF_UP]);

Returns the result of rounding val according to the specified precision precision (the number of numbers after decimal decimal points). precision can also be a negative number or zero (default value). Round floating point numbers

<?php
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.05
echo round(5.055, 2);  // 5.06
?> 

mode example

<?php
echo round(9.5, 0, PHP_ROUND_HALF_UP);  // 10
echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9
echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10
echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9
 
echo round(8.5, 0, PHP_ROUND_HALF_UP);  // 9
echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9
?>

PS: Here are a few calculation tools for you to refer to:

Online unary function (eq) solution calculation tool:
http://tools./jisuanqi/equ_jisuanqi

Scientific Calculator Online Use_Advanced Calculator Online Calculator:
http://tools./jisuanqi/jsqkexue

Online Calculator_Standard Calculator:
http://tools./jisuanqi/jsq

For more information about PHP related content, please check out the topic of this site:Summary of PHP mathematical operation skills》、《Summary of PHP operations and operator usage》、《Summary of usage of php strings》、《Complete collection of PHP array (Array) operation techniques》、《PHP data structure and algorithm tutorial》、《Summary of PHP Programming Algorithm"and"Summary of usage of php regular expressions

I hope this article will be helpful to everyone's PHP programming.