round(): Rounding off variable values in PHP

$number=25.66745;
echo "The number = ". $number // will display 25.66745 
echo "<br>Rounded value of the number = ".round($number,2); // will display25.67 
echo "<br>Rounded value of the number = ".round($number); // will display 26 
We can round off variable values to a whole number or to some value with precision. You can read the article on number formatting to know how to format numbers using PHP.
Some time we may use php number formatting function to display a proper formatted number.

We can round off the number to lower value is by using floor function and we can also round off to next higher number by using ceil function in PHP

Here is a comparison between ceil(), floor() and round() function. For different input numbers we will get different values by using these functions.
ValueFloor()ceil()round()
3.7344
3.4343
3.5344
3.48343
3.62344
2222
-8.7-9-8-9
-9.5-10-9-10
-9.3-10-9-9
-9.49-10-9-9
-9.61-10-9-10
-9-9-9-9




PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer