src/content/docs/linter/rules/use-number-to-fixed-digits-argument.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.8.0` - Diagnostic Category: [`lint/suspicious/useNumberToFixedDigitsArgument`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`unicorn/require-number-to-fixed-digits-argument`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/require-number-to-fixed-digits-argument.md){
"linter": {
"rules": {
"suspicious": {
"useNumberToFixedDigitsArgument": "error"
}
}
}
}
Enforce using the digits argument with Number#toFixed().
When using Number#toFixed() explicitly specify the number of digits you want to appear after the decimal point,
to avoid unexpected results, rather than relying on its default value of 0.
const string = number.toFixed();
const string = foo.toFixed(0);
const string = foo.toFixed(2);
This rule always assumes that toFixed is called on a number.
It does not check the type of the callee.