1

I'm doing some calculations in PHP and I'm getting numbers that look like 0.20758605003357.

How can I round that so the output is 0.21 in that case. Or more generally, so that the number, whatever it is, is rounded to the hundredths' place.

4

2 に答える 2

3

use PHP's roundfunction:

echo round($number, 2);

see: http://www.php.net/manual/en/function.round.php

于 2013-03-24T23:19:47.000 に答える
2
number_format($number,2);

the second parameter is how many digits after the decimal.

Also, there is money_format (if you want it rounded). in USD:

money_format('%i',$number);
于 2013-03-24T23:18:09.563 に答える