I was trying to round UP a decimal with the code I found below, but it doesn't seem to work properly in python(django). Here is the code:
import math
def round_up(n, decimals=0):
multiplier = 10 ** decimals
return math.ceil(n * multiplier) / multiplier
Here are some of the results I get when I run the function:
print(round_up(20.232, 2))
print(round_up(20.211, 2))
print(round_up(20.4, 2))
20.24
20.22
20.4
However, for some reason, I get a weird value when I input 80.4. I am getting 80.41 instead of 80.4:
print(round_up(80.4, 2))
80.41
Is there any other way I can round up decimals in python(django)? I have gotten this off the internet, so there might be some other problems other than the one I mentioned above(inputting 80.4). Basically, I just want to round up a decimal to the second decimal point like above(but of course rounding up 80.4 or 20.3 would just be 80.4 and 20.3 respectively). Thank you, and please leave any questions you have.