Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1002 Bytes

require-number-to-fixed-digits-argument.md

File metadata and controls

42 lines (30 loc) · 1002 Bytes

Enforce using the digits argument with Number#toFixed()

This rule is part of the recommended config.

🔧 This rule is auto-fixable.

It's better to make it clear what the value of the digits argument is when calling Number#toFixed(), instead of relying on the default value of 0.

Fail

const string = number.toFixed();

Pass

const string = foo.toFixed(0);
const string = foo.toFixed(2);
const integer = Math.floor(foo);
const integer = Math.ceil(foo);
const integer = Math.round(foo);
const integer = Math.trunc(foo);