- Forums
- PHP
- PHP Programming How To Make Round Numbers From Float Numbers Rounding
this page shows you about php programming and how to make round number from float number in your php, the math is very simple i will explain the code with example written in php script so you can test your scripts [985], Last Updated: Sat May 18, 2024
bigger_travis
Mon Dec 04, 2006
0 Comments
1621 Visits
round() function:round Rounds a float number
[This post sponsered by www.webune.com]if you are a php programmer, you will often need to round numbers from float numbers. What are float numbers? floats are numbers with a decimal point. for example: 2.49 is a float, where as 2 is the rounded number. Its often useful to use the round() function in php because it makes your code run smooter, specially in non-mathematical sites.
it is supported in PHP 3, PHP 4 and PHP 5
Description
float round ( float val [, int precision] )
Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).
here are some exaples you can use to get an idea;
CODE:
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?>
if you need more help on this, php.net is a great site to get information about php functions. i use it all the time
you can get more info on this function on:
http://www.php.net/manual/en/function.round.php
hope this helps.