PDA

View Full Version : [PHP] Displaying numbers two the whole number



Moh
10-04-2008, 02:28 PM
Does any one know to make it so if the number has a decimal, it displays it to the nearest number. e.g.

1.4 = 1
2.7 = 3
4.3 = 4
8.8 = 9
3.1 = 3

Thanks :)

Florx
10-04-2008, 02:48 PM
<?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
?>
http://uk2.php.net/round

Moh
10-04-2008, 03:17 PM
<?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
?>
http://uk2.php.net/round
Thanks, I didn't know what the name of it was :P
+Rep

Hum, just noticed I spelt to as two *slaps self*

Want to hide these adverts? Register an account for free!