1 # Disallow Number Literals That Lose Precision (no-loss-of-precision)
3 This rule would disallow the use of number literals that immediately lose precision at runtime when converted to a JS `Number` due to 64-bit floating-point rounding.
7 In JS, `Number`s are stored as double-precision floating-point numbers according to the [IEEE 754 standard](https://en.wikipedia.org/wiki/IEEE_754). Because of this, numbers can only retain accuracy up to a certain amount of digits. If the programmer enters additional digits, those digits will be lost in the conversion to the `Number` type and will result in unexpected behavior.
9 Examples of **incorrect** code for this rule:
12 /*eslint no-loss-of-precision: "error"*/
14 const x = 9007199254740993
15 const x = 5123000000000000000000000000001
16 const x = 1230000000000000000000000.0
17 const x = .1230000000000000000000000
18 const x = 0X20000000000001
19 const x = 0X2_000000000_0001;
22 Examples of **correct** code for this rule:
25 /*eslint no-loss-of-precision: "error"*/
30 const x = 12300000000000000000000000
31 const x = 0x1FFFFFFFFFFFFF
32 const x = 9007199254740991
33 const x = 9007_1992547409_91