tags:

views:

50

answers:

3

For example:
(a)123 / (b)1000 = (c)0,123
echo c must be 0,12

How can this be done ?

+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
Fastest comment is the most complete! :-)
PhiLho
nice,how can i make a number_format rule for all the numbers so i don't have to declare every number ?
zoro
@zoro: You can define your own function: `function myFormat($n) { return number_format($n, 2); }`
Daniel Egeberg
A: 

Use number_format http://php.net/number_format

robertbasic
A: 

Using sprintf() can be a way to do that.

PhiLho