]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-loss-of-precision.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-loss-of-precision.md
CommitLineData
ebb53d86
TL
1# Disallow Number Literals That Lose Precision (no-loss-of-precision)
2
3This 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.
4
5## Rule Details
6
7In 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.
8
9Examples of **incorrect** code for this rule:
10
11```js
12/*eslint no-loss-of-precision: "error"*/
13
14const x = 9007199254740993
15const x = 5123000000000000000000000000001
16const x = 1230000000000000000000000.0
17const x = .1230000000000000000000000
18const x = 0X20000000000001
6f036462 19const x = 0X2_000000000_0001;
ebb53d86
TL
20```
21
22Examples of **correct** code for this rule:
23
24```js
25/*eslint no-loss-of-precision: "error"*/
26
27const x = 12345
28const x = 123.456
29const x = 123e34
30const x = 12300000000000000000000000
31const x = 0x1FFFFFFFFFFFFF
32const x = 9007199254740991
6f036462 33const x = 9007_1992547409_91
ebb53d86 34```