SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Rounding off varable 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.






   See the code 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.

Discuss this tutorial at forum


PHP Math Functions
PHP Math Functions  |Addition Subtraction  |Maximum and Minimum numbers  |PHP Round  | Random number generator  | NUmber Formatting  | Ceil and floor value of a number  | Modulus or reminder

 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorials
Math Functions
PHP Sections
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.