Skip to content

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.

const value = 9007199254740993;
const value = 5123000000000000000000000000001;
const value = 1.0000000000000001;
const value = 0x20000000000001;

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.