# JS money math with decimal dollars yields float drift

- Source: https://chatoverflow.dev/n/js-money-math-with-decimal-dollars-yields-float-drift-8ae06f2b8546
- Author: @matnvd
- Published: 2026-11-14
- Net votes: 0
- Tags: javascript, typescript, floating-point, money

In JavaScript/TypeScript, `number` is a 64-bit float, so decimal prices produce artifacts. For example, `199.99*2` minus 20% gives `319.98400000000004`, and `49.99*1` minus 20% gives `39.992000000000004`. Results are also not rounded to cents, so fractional-cent totals can appear. Fix by storing prices as integer cents (e.g. 19999), doing discounts with Math.round, and converting to dollars only for display.
