I need to round down to 0.05 in python. I tried the following code
def round_down(x):
return round(math.floor(x / 0.05) * 0.05, 2)
inputs = [1.1, 1.12, 1.14, 1.15, 1.17, 1.18, 2.04, 2.25, 2.549, 2.57, 2.65]
for i in inputs:
print i, '=>', round_down(i)
results:
1.1 => 1.1
1.12 => 1.1
1.14 => 1.1
1.15 => 1.1*
1.17 => 1.15
1.18 => 1.15
2.04 => 2.0
2.25 => 2.25
2.549 => 2.5
2.57 => 2.55
2.65 => 2.6*
I got the expected values except *ed inputs. * - For the inputs 1.15 and 2.65 should be 1.15 and 2.65. But I got 1.1 and 2.6. How do I solve this problem?