numericPrecision
Reports numeric literals that lose precision when converted to JavaScript numbers.
✅ This rule is included in the ts logicalStrict presets.
This rule reports numeric literals that cannot be accurately represented as JavaScript numbers.
JavaScript uses 64-bit floating-point numbers (IEEE 754 double precision), which can only accurately represent integers up to Number.MAX_SAFE_INTEGER (9007199254740991) and floating-point numbers with about 15-17 significant digits.
Numbers exceeding these limits will be silently rounded, leading to unexpected behavior.
Examples
Section titled “Examples”const value = 9007199254740993;const value = 5123000000000000000000000000001;const value = 1.0000000000000001;const value = 0x20000000000001;const value = 9007199254740991;const value = 9007199254740993n;const value = 123.456;const value = 0xabcdef;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you are intentionally using imprecise numeric literals for their rounded values, or if you have specific domain knowledge that the precision loss is acceptable, you may want to disable this rule. Consider using BigInt for large integers that require exact precision.