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

    Both of these are valid notation. Json spec also says that numbers are floats, so it’s perfectly acceptable to denote them this way. This is why currency should never use a number notation, and instead use a string. If it must be precise, use a string.

    • 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.