Lint Rules

noPrecisionLoss (since v11.0.0)

Disallow literal numbers that lose precision

Examples

Invalid

const x = 9007199254740993
nursery/noPrecisionLoss.js:1:11 lint/nursery/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This number literal will lose precision at runtime.
  
  > 1 │ const x = 9007199254740993
             ^^^^^^^^^^^^^^^^
    2 │ 
  
   The value at runtime will be 9007199254740992
  
const x = 5123000000000000000000000000001
nursery/noPrecisionLoss.js:1:11 lint/nursery/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This number literal will lose precision at runtime.
  
  > 1 │ const x = 5123000000000000000000000000001
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   The value at runtime will be 5123000000000000000000000000000
  
const x = 1230000000000000000000000.0
nursery/noPrecisionLoss.js:1:11 lint/nursery/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This number literal will lose precision at runtime.
  
  > 1 │ const x = 1230000000000000000000000.0
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   The value at runtime will be 1230000000000000000000000
  
const x = .1230000000000000000000000
nursery/noPrecisionLoss.js:1:11 lint/nursery/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This number literal will lose precision at runtime.
  
  > 1 │ const x = .1230000000000000000000000
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   The value at runtime will be 0.123
  
const x = 0X20000000000001
nursery/noPrecisionLoss.js:1:11 lint/nursery/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This number literal will lose precision at runtime.
  
  > 1 │ const x = 0X20000000000001
             ^^^^^^^^^^^^^^^^
    2 │ 
  
   The value at runtime will be 9007199254740992
  
const x = 0X2_000000000_0001;
nursery/noPrecisionLoss.js:1:11 lint/nursery/noPrecisionLoss ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   This number literal will lose precision at runtime.
  
  > 1 │ const x = 0X2_000000000_0001;
             ^^^^^^^^^^^^^^^^^^
    2 │ 
  
   The value at runtime will be 9007199254740992
  

Valid

const x = 12345
const x = 123.456
const x = 123e34
const x = 12300000000000000000000000
const x = 0x1FFFFFFFFFFFFF
const x = 9007199254740991
const x = 9007_1992547409_91