• Dark ArcA
    link
    fedilink
    English
    arrow-up
    27
    ·
    edit-2
    7 months ago

    Comparing floats for equality is generally a bad idea anyways.

    Floats should really only be used for approximate math. You need something like Java’s BigDecimal or BigInteger to handle floating point math with precision.

    Looks like this is the equivalent for Python:

    https://docs.python.org/3/library/decimal.html

    • Cethin@lemmy.zip
      link
      fedilink
      English
      arrow-up
      5
      arrow-down
      1
      ·
      7 months ago

      Comparing is fine, but it should be fuzzy. Less than and greater than are fine, so you basically should only be checking for withing a range of values, not a specific value.