How to round a decimal number to nearest 5 or nearest 10 in php
Thanks its works
Sohail Anwar
2010-07-22 11:41:18
If this is an optimal solution for your problem please flag the answer.
Dennis Haarbrink
2010-07-22 11:50:58
A:
For the special case of nearest 10, you can use a negative precision:
$new = round($num, -1)
pascal
2010-07-22 13:34:12
+1
A:
Multiply by 2, round to the nearest 10 (see pascal's answer), then divide by 2. Avoid dividing/multiplying by 5 to do this since float representation will interfere with the accuracy of your results.
Ignacio Vazquez-Abrams
2010-07-22 13:38:47