Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1023 Bytes

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

File metadata and controls

42 lines (29 loc) · 1023 Bytes

Enforce using the digits argument with Number#toFixed()

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

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);