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.
Rounding
Moderator: General Moderators
Re: Rounding
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()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Re: Rounding
Thanks - I am displying a price so the trailing 0 is required in this case. The number_format function works perfectly.
Rob.
Rob.
Re: Rounding
If it's a price, you can also use money_format().
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.