I am doing a simple comparison between a string value and floats minValue and maxValue to check if value is outside of a certain range
if float(value) < minValue or float(value) > maxValue:
# show error and exit
It works fine unless value and minValue are the same. So when value = -1.234
and minValue = -1.234
, it goes inside the if statement because for some reason -1.234 < -1.234
evaluates to True
.
My workaround is to use Decimal
if Decimal(value) < Decimal(str(minValue)) or Decimal(str(value) > Decimal(maxValue):
# show error and exit
But Decimal(str(minValue))
looks a little messy so I'm wondering if there is a better way of comparing two floats that won't fail when they are the same value without having to do float to string to decimal conversion first.
EDIT
value
comes from a csv file, so there is no truncation there. What you see is what you get. minValue
is, however, a result of a polynomial function, but I don't believe there is any truncation or rounding there.
Here's the function to calculate minValue
f = numpy.poly1d(coefficients)
x = range(int(low), int(high), 1)
y = f(x)
minValue = min(y)
maxValue = max(y)