SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Rounding off variable values in PHP

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. For simple rounding here is the code to do all that. WE will store the value in a variable and then display by rounding off it by using round function.

Sample code for rounding data below

$number=25.66745;
echo "The number = ". $number;               // will display 25.66745
echo "<br>Rounded value of the number = ".round($number,2);     // will display 25.67
echo "<br>Rounded value of the number = ".round($number);     // will display 26

Some time we may use php number formatting function to display a proper formatted number.


Visit the links below to see other php math functions.



Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Math Functions
PHP Sections