This article mainly introduces how to use PHP rounding-related functions, namely intval() function, round() function, ceil() function, floor() function. I hope it will be helpful to friends who need it. Helps!
1. intval() function
Code example:
<?php $num = 3.1415926; $num2 = 3.6; echo intval($num).'<br>'; echo intval($num2); echo "<hr>";
Output:
3 3
2. round() function
Code example:
<?php $num = 3.1415926; $num2 = 3.6; echo round($num).'<br>'; echo round($num2); echo "<hr>";
Output:
3 4
3. ceil() function
<?php $num = 3.1415926; $num2 = 3.6; echo ceil($num).'<br>'; echo ceil($num2); echo "<hr>";
Output:
4 4
4. Floor() function
<?php $num = 3.1415926; $num2 = 3.6; echo floor($num).'<br>'; echo floor($num2);
Output:
3 3
Summary of PHP rounding function:
intval() function means to obtain the integer value of a variable.
The round() function represents rounding of floating point numbers.
The ceil() function represents further rounding.
The floor() function represents rounding by rounding.
Related recommendations: "PHP Tutorial"
The above is the detailed content of Detailed explanation of PHP rounding function code. For more information, please follow other related articles on the PHP Chinese website!