Hvor can I en python do the following rounding:
Round to the nearest 05 decimal
7,97 -> 7,95
6,72 -> 6,70
31,06 -> 31,05
36,04 -> 36,
Using lambda function:
>>> nearest_half = lambda x: round(x * 2) / 2 >>> nearest_half(5.2) 5.0 >>> nearest_half(5.25) 5.5 >>> nearest_half(5.26) 5.5 >>> nearest_half(5.5) 5.5 >>> nearest_half(5.75) 6.0