• @call_me_xale@lemmy.zip
    link
    fedilink
    10
    edit-2
    1 month ago

    More devs should learn to use Rational types. A pretty large majority of the numbers that people care about in real life can easily be represented by a ratio of integers, and they allow math with perfect precision.

    eta: even monetary types are just a form of Rational, with the denominators clamped to powers of ten

    • @boonhet@lemm.ee
      link
      fedilink
      73 months ago

      Or just BigDecimal or an equivalent if rational types aren’t easy to use in your language (e.g if you’d have to literally enter the denominator and numerator).

    • @Quetzalcutlass@lemmy.world
      link
      fedilink
      English
      33 months ago

      Someone posted this article a while back that goes into more detail on some alternatives, as well as contains one of the best and most intuitive explanations of floating point that I’ve ever read.