PHP Programming How To Make Round Numbers From Float Numbers Rounding
php programming how to make round numbers from float numbers rounding
php, programming, how, to, make, round, numbers, from, float, numbers, rounding
PHP Programming How To Make Round Numbers From Float Numbers Rounding
Post Description: php programming how to make round numbers from float numbers rounding
POST# 357
Posted On: Fri Feb 29, 2008 12:01 pm
bigger_travis
Topic: PHP Programming How To Make Round Numbers From Float Numbers Rounding
round() function:

round Rounds a float number

[This post sponsered by www.webune.com]
post picture

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.


No Repies
(0) Comments for PHP Programming How To Make Round Numbers From Float Numbers Rounding

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload