• GissaMittJobb@lemmy.ml
        link
        fedilink
        arrow-up
        2
        ·
        7 days ago

        You can’t use it if you ever want to do any operations on said money, due to the loss of prescision.

        Enums are not a good idea for the currencies either.

        • FizzyOrange@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          7 days ago

          Yes you can. You’re vastly underestimating the size of an f64. Give me a concrete example of a money operation that fails with f64 (for normal companies; assuming you aren’t a stock exchange or Visa or whatever).

          Enums are not a good idea for the currencies either.

          Why not?

          • GissaMittJobb@lemmy.ml
            link
            fedilink
            arrow-up
            3
            ·
            6 days ago

            Yes you can. You’re vastly underestimating the size of an f64. Give me a concrete example of a money operation that fails with f64 (for normal companies; assuming you aren’t a stock exchange or Visa or whatever).

            0.1f64 + 0.2f64 != 0.3f64

            Why not?

            Encoding in assumptions about a fixed amount of supported currencies in a system is broadly speaking not a good idea

            • FizzyOrange@programming.dev
              link
              fedilink
              arrow-up
              1
              ·
              5 days ago

              0.1f64 + 0.2f64 != 0.3f64

              It does if you round it to the nearest penny.

              Encoding in assumptions about a fixed amount of supported currencies in a system is broadly speaking not a good idea

              Most sensible programming languages allow enums to be non-exhaustive.