Disallow literal numbers that lose precision
The "extends": "eslint:recommended"
property in a configuration file enables this rule
This rule would disallow the use of number literals that lose precision at runtime when converted to a JS Number
due to 64-bit floating-point rounding.
In JS, Number
s are stored as double-precision floating-point numbers according to the IEEE 754 standard. 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.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
This rule was introduced in ESLint v7.1.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/no-loss-of-precision