Re:How to compare floats in Python
by zokier on Wednesday March 30, 2022 @02:46PM
(#30859236)
wouldn't just
work as well?
[ Parent
| on HN ]
Sorry, I am doing stuff in the function... here is one of the old ones from code I can share
def dec(value, prec=4):
"""Return the given value as a decimal rounded to the given precision."""
if value is None:
return Decimal(0)
value = Decimal(value)
ret = Decimal(str(round(value, prec)))
if ret.is_zero():
# this avoids stuff like Decimal('0E-8')
return Decimal(0)
return ret