• DarkAri@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    5 hours ago

    You could just limit the precision of the float. If you are writing banking software or something you could just add a special case to flip flop the remainder or something. I think pretty much all modern languages support this. You should also be using doubles for any numbers that could potentially grow really large like fiat currencies. The issues with floats really is that it will often favor precision over range. You could end up with lots of numbers after a decimal and very little integer range which could cause overruns or something.

    • TehPers@beehaw.org
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      5 hours ago

      The article goes into depth about what you should be using. Floats and doubles are not designed for use with base 10 fractions. They’re good at estimating them, but not accurate enough for real financial use.

      There’s also not much reason to reinvent the wheel for an already solved problem. Many languages have this data type already built into the language, and the rest usually have it available through a package.