• iocase@lemmy.zip
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    3 months ago

    It’s easier to just compute the smallest atomic amount of a currency, usually cents, using integers. Then display it as full dollars, pounds, euros—what have you—to the end user. For Division you need some way to account for the remainder across transactions, but that’s probably rules from accounting and not integer math.

    What’s the benefit of Dinero? Is that like the financial equivalent of the iseven() dependency?

    • Zarobi@aussie.zone
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 months ago

      JavaScript is a bit funny and doesn’t actually have native integers… every number is a floating point, which means even whole number math gets weird sometimes. Not often, but enough that cents were lost and people were upset.

      I haven’t looked at how Dinero works under the hood, but I never had any problems at all with it after we started using it. Front end works in cents, back end works in decimal, is what I’d suggest for anyone else reading this. Statically typed languages are much easier to control and you don’t need a library at all if you’re careful.