Skip to content

no-loss-of-precision

Reports a number literal that the 64-bit double it becomes does not hold exactly: 9007199254740993 (above 2^53), 0x20000000000001, a value that is too large (1e400, becomes Infinity) or too small (2e-400, becomes 0). 9007199254740992, 0.1, a number that has an exact double (1e20) and BigInt literals (123n) are not reported.

JavaScript rounds such a literal when the file is read, so the program computes with another number than the one written, with no error. Integers above 2^53 lose their last digits, which breaks ids and counters.

To fix, use a BigInt literal (9007199254740993n), keep the value in a string, or write the number the double really holds.

Reported
...
var p = 9007199254740993, q = 0.1, r = 5123000000000000000000000000001, s = 0x20000000000001, t = 0x1fffffffffffff;
var u = 12345678901234567890, v = 0.30000000000000004, w = 1_000, x = 0.1000000000000000055511151231257827, y = 1e3;
js:
lint:
rules:
no-loss-of-precision: warn # off, warn (default), error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-loss-of-precision in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-loss-of-precision full