I am looking to round up in nearest 0.05 increments. For example, if I have a number 1.01, it must be rounded up to 1.05. How can I do this?
I'm using Python 3.7.
I would solve this in the following way:
import math
a = 1.01
b = a*20
c = math.ceil(b)
d = c/20
print(d)
I know that rounding to the nearest integer value is easy to do, so I transform my number so that instead of incrementing by 0.05
I want to increment by 1
. This is done by multiplying 20 (as 0.05*20=1
). I can then round my 20x
higher number to the nearest integer, and divide by 20 to get what I'm looking for.
Also note math
is included in Python so no need to download a new module!