dogear

enter for all results · esc to close

Never Use Floats for Money

husobee.github.iosite

“This is precisely the problem we have when trying to represent 10^-1, or 0.1 in binary. There is not an exact binary representation of 0.1 or 0.01.”

from
Billing
added
2026-10-10
likes
0

similar

  1. Why not use Double or Float to represent currency? web.archive.org

    Because of precision: floats and doubles cannot accurately represent the base 10 multiples that we use for money.

  2. Floating Point Math 0.30000000000000004.com

    “Your language isn't broken, it's doing floating point math. (…) This is why, more often than not, 0.1 + 0.2 != 0.3.”

  3. Floating point number floating-point-gui.de

    This representation can encode numbers at very different magnitudes with a limited amount of digits by letting the radix point float instead of being fixed in place.

  4. Twenty five thousand dollars of funny money web.archive.org

    Same error as above at Google Ads, or the danger of separating your pennies from your dollars, where $250 internal coupons turned into $25,000. My advice: get rid of integers and floats for monetary values. Use decimals. Or fallback to strings and parse them, don't validate.

  5. money github.com

    Immutable monetary amounts and exchange rates with panic-free arithmetic.

  6. decimal github.com

    Immutable decimal numbers with panic-free arithmetic.

Billing › Business Intelligence > Data Engineering: ““This is precisely the problem we have when trying to represent 10^-1, or 0.1 in binary. There is not an exact binary representation of 0.1 or 0.01.””