# no-loss-of-precision

> Disallow number literals that cannot be stored exactly as written

A JavaScript number holds 15 to 17 significant digits. A literal with more is rounded without a warning. `9007199254740993` becomes `9007199254740992`, so an ID typed into the code points at another record. A literal that's too large becomes `Infinity`, and one that's too small becomes `0`.

A number with a fractional part isn't reported by default. The extra digits of `3.14159265358979323846` only round it to the closest number there is, which is what you'd expect.

This rule is on by default.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-loss-of-precision" = "off" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-loss-of-precision" = ["error", {
  ignoreDecimals = true,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 4} */}
```js
const orderId = 9007199254740993;
const mask = 0x20000000000001;
const huge = 1e400;
const tiny = 1e-400;
```

Not reported:

{/* good */}
```js
const orderId = 9007199254740993n;
const orderKey = "9007199254740993";
const pi = 3.14159265358979323846;
const mask = 0x1fffffffffffff;
const huge = Infinity;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `ignoreDecimals` | `true` | Don't report a number that has a fractional part. |

Only `bun lint` has this option. With an ESLint config file decimals are reported, as in ESLint.

{/* bad {"options": [{"ignoreDecimals": false}]} */}
```js
const pi = 3.14159265358979323846;
```
