Round Function in PHP
In this article, we will see how to use the round function in php.
The round() function is used to return the given value to the round of the nearest integer
echo round(2.8); //3
Example:
<?php
echo round(2.3); //2
echo round(2.4); //2
echo round(2.5); //3
echo round(2.8); //3
?>
- See the above example code, we print the round() function by passing the value “2.3”, the nearest round integer of 2.3 is 2, so it returns the value 2.
- Then we printed the round() function by passing the value “2.4”, the nearest round integer of 2.4 is 2, so it returns the value 2.
- If we give a decimal greater than >4, the round() function will return the greatest nearest value. So, if we pass the value “2.5”, it returns value 3.