• @[email protected]
    link
    fedilink
    English
    126 days ago

    If you’re doing any work with accounting, or writing test cases with floating point values.

    • DreamButt
      link
      English
      166 days ago

      Please tell me you aren’t using floating points with money

        • @Womble
          link
          English
          3
          edit-2
          6 days ago

          Eh, if you use doubles and you add 0.000314 (just over 0.03 cents) to ten billion dollars you have an error of 1/10000 of a cent, and thats a deliberately perverse transaction. Its not ideal but its not the waiting disaster that using single precision is.

        • @[email protected]
          link
          fedilink
          English
          106 days ago

          Instead of representing $1.102 as 1.102 your store it as 1012 (or whatever precision you need) and divide by 1000 only for displaying it.

          • @[email protected]
            link
            fedilink
            English
            16 days ago

            So if you handle different precisions you also need to store the precision/exponent explicitly for every value. Or would you sanitise this at input and throw an exception if someone wants more precision than the program is made for?

            • @[email protected]
              link
              fedilink
              English
              66 days ago

              It depends on the requirements of your app and what programming language you use. Sometimes you can get away with using a fixed precision that you can assume everywhere, but most common programming languages will have some implementation of a decimal type with variable precision if needed, so you won’t need to implement it on your own outside of university exercises.

              • @[email protected]
                link
                fedilink
                English
                26 days ago

                Okay thank you. I was wondering because for stuff like buying electricity, gas or certain resources, parts etc. there is prices with higher precision in cents, but the precision would not be identical over all use cases in a large company.

            • @[email protected]
              link
              fedilink
              English
              56 days ago

              No exponent, or at least a common fixed exponent. The technique is called “fixed point” as opposed to “floating point”. The rationale is always to have a known level of precision.

    • Cyborganism
      link
      fedilink
      English
      15 days ago

      No. I don’t have to remember that.

      I just have to remember the limits and how you can break the system. You don’t have to think about the representation.