How can I do the following rounding in python:
Round to the nearest 0.05 decimal
7,97 -> 7,95
6,72 -> 6,70
31,06 -> 31,05
36,04 -> 36,05
5,25 -> 5,25
Hope it makes sense.
def round_to(n, precision): correction = 0.5 if n >= 0 else -0.5 return int( n/precision+correction ) * precision def round_to_05(n): return round_to(n, 0.05)
2.1m questions
2.1m answers
60 comments
57.0k users