forcing variable to 2 decimal places<

windows

Guest
I am trying to calculate percentages of money.

If the gross is $500.55 and I multiply by 12%, I want to get 60.07, or even 60.06, but NOT 60.066. How can I do this? Is there anyway to limit the number of decimal places?round($thingtoberounded,$howmanyplaces)Aaron - here:

<!-- m --><a class="postlink" href="http://uk2.php.net/manual/en/function.number-format.php">http://uk2.php.net/manual/en/function.number-format.php</a><!-- m -->

Cheers,
HKThanks jokerman, I was overlooking the obious.

Horus_kol, that would work too, but it seems to do it as a string.Originally posted by AaronCampbell
Thanks jokerman, I was overlooking the obious.

Horus_kol, that would work too, but it seems to do it as a string.
haha happens to the best of usyou will get some wierd results with round() best bet is to use this

$format = sprintf("%01.2f", $number);
echo $format;

<!-- m --><a class="postlink" href="http://uk2.php.net/manual/en/function.sprintf.phpOriginally">http://uk2.php.net/manual/en/function.s ... Originally</a><!-- m --> posted by scoutt
you will get some wierd results with round()

What kind of "weird results" might occur? I have it all done with round, and it SEEMS to work fine, but I don't want any problems in the future.because if you have 30.00 it will read it as 30.0 and some other ones I can't remember. it just isn't very consistant. but if you are not having any problems then cool, no need to make the change.
 
Back
Top