tags:

views:

67

answers:

3

How to round a decimal number to nearest 5 or nearest 10 in php

+2  A: 

$new = round($num / 10, 0) * 10 rounds to nearest 10

Dennis Haarbrink
Thanks its works
Sohail Anwar
If this is an optimal solution for your problem please flag the answer.
Dennis Haarbrink
A: 

For the special case of nearest 10, you can use a negative precision:

$new = round($num, -1)
pascal
+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