News for hackers. Stuff that matters.
Re:How to compare floats in Python by zokier on Wednesday March 30, 2022 @02:46PM (#30859236)
wouldn't just

    from decimal import Decimal as d
work as well?
Re:How to compare floats in Python by leetrout on Wednesday March 30, 2022 @04:53PM (#30860646)
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