For example:
(a)123 / (b)1000 = (c)0,123
echo c must be 0,12
How can this be done ?
views:
50answers:
3
+4
A:
Use round(), sprintf() or number_format().
Examples:
<?php
$res = 123/1000;
printf('%.2f', $res);
echo round($res, 2);
echo number_format($res, 2);
?>
Daniel Egeberg
2010-08-01 09:15:39
Fastest comment is the most complete! :-)
PhiLho
2010-08-01 09:18:33
nice,how can i make a number_format rule for all the numbers so i don't have to declare every number ?
zoro
2010-08-01 09:38:21
@zoro: You can define your own function: `function myFormat($n) { return number_format($n, 2); }`
Daniel Egeberg
2010-08-01 09:52:56