Page 1 of 1

Rounding

Posted: Thu Nov 12, 2009 9:25 am
by spacebiscuit
Hi,

Using the round function I am rounding number to two decimal places. This works fine until the unit is a 0.

So for example: 10.10 rounds to 10.1

How can I ensure the unit remains if it is a 0.

Thanks in advance,

Rob.

Re: Rounding

Posted: Thu Nov 12, 2009 10:16 am
by pickle
10.10 is exactly the same as 10.1, so rounding isn't changing the value. PHP removes superfluous trailing zeros. I'd leave the zero off for the purposes of doing math do it. When you want to display it, use number_format()

Re: Rounding

Posted: Thu Nov 12, 2009 10:24 am
by spacebiscuit
Thanks - I am displying a price so the trailing 0 is required in this case. The number_format function works perfectly.

Rob.

Re: Rounding

Posted: Thu Nov 12, 2009 10:31 am
by pickle
If it's a price, you can also use money_format().