I need to truncate a decimal at the hundredths place without rounding. I'm using the the method:
y = 78.459
x = int(y * 100) / 100
which comes back as 78.45
. As it should.
However, if I do
y = 5.10
x = int(y * 100) / 100
it come back as 5.09
, when it should be 5.10
I know that this is a representation error, due to the floating-point inaccuracies in Python, but I don't know how to fix it. If anyone can either help me figure out how to fix representation errors or maybe find a better way to truncate at the hundredths place, I would really appreciate it. Thanks