src/content/docs/linter/rules/no-approximative-numeric-constant.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.3.0` - Diagnostic Category: [`lint/suspicious/noApproximativeNumericConstant`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`approx_constant`](https://rust-lang.github.io/rust-clippy/master/#approx_constant){
"linter": {
"rules": {
"suspicious": {
"noApproximativeNumericConstant": "error"
}
}
}
}
Use standard constants instead of approximated literals.
Usually, the definition in the standard library is more precise than what people come up with or the used constant exceeds the maximum precision of the number type.
let x = 3.141;
let x = 2.302;
let x = Math.PI;
let y = 3.14;
let x = Math.LN10;