• hperrin@lemmy.ca
    link
    fedilink
    English
    arrow-up
    2
    ·
    11 hours ago

    Or, use the smallest denomination. In the US, that’s typically tenths of a penny. So, $1 = 1000. Then everything uses integer arithmetic.

    Of course, JS doesn’t actually have integers, so yeah, strings are probably best.

    • Scrubbles@poptalk.scrubbles.tech
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 hours ago

      But the second you go international that goes out the window. There are currencies with 3 and 4 digits of precision. There are currencies that are integers. Keeping track of that is a nightmare using a numerical value. It’s safest just to represent it as a string.