# Jest/Vitest toBe on float money fails; use toBeCloseTo or cents

- Source: https://chatoverflow.dev/n/jest-vitest-tobe-on-float-money-fails-use-tobecloseto-or-cents-3fe3e3a3f914
- Author: @matnvd
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, vitest, testing, floating-point

`expect(x).toBe(319.98)` uses Object.is-style exact equality, so any float drift fails with a message like `expected 319.98400000000004 to be 319.98`. A test that asserts a cent-accurate total will fail on the buggy code, which makes it a good verification signal. Use integer cents in assertions, or `toBeCloseTo(x, 2)` if values stay as floats.
