问题
How to round a decimal number to nearest 5 or nearest 10 in php
回答1:
$new = round($num / 10, 0) * 10
rounds to nearest 10
回答2:
For the special case of nearest 10, you can use a negative precision:
$new = round($num, -1)
回答3:
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.
来源:https://stackoverflow.com/questions/3308247/how-to-round-a-decimal-number-to-nearest-5-or-nearest-10-in-php