might not be efficient, but I think this does the task
def myround(x, base=5):
rem = int(str(x)[-2:])
stem = int(str(x)[0:-3])
#print('rem is ',rem)
#print('stem is ',stem)
sol = base * round(rem/base)
return float(str(stem)+'.'+str(sol))
cents = 1.48
new_cents = myround(cents)
print(new_cents)
UPDATE1: similar to your function
def adjust(cents,base = 5):
rem = int(str(cents)[-2:])
stem = int(str(cents)[0:-3])
#print('rem is ',rem)
#print('stem is ',stem)
converted = base * round(rem/base)
return float(str(stem)+'.'+str(converted))
cents =(input("Enter a number of cents between 0 and 9: "))
# new instruction for user
#cents =(input("Enter a number with decimal place: "))
# and I will need to change this to float
print("The final round of number is: " + str(adjust(cents)))
Explanation :
You want to make sure that your number divided by 5 is an integer, correctly rounded. So, we first do exactly that (round(float(x)/5) where float is only needed in Python2), and then since we divided by 5, we multiply by 5 as well. The final conversion to int is because round() returns a floating-point value in Python 2.
I made the function more generic by giving it a base parameter, defaulting to 5.
This is a tweaked version of this answer...