]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-floating-decimal.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-floating-decimal.md
CommitLineData
eb39fafa
DC
1# Disallow Floating Decimals (no-floating-decimal)
2
3Float values in JavaScript contain a decimal point, and there is no requirement that the decimal point be preceded or followed by a number. For example, the following are all valid JavaScript numbers:
4
5```js
6var num = .5;
7var num = 2.;
8var num = -.7;
9```
10
11Although not a syntax error, this format for numbers can make it difficult to distinguish between true decimal numbers and the dot operator. For this reason, some recommend that you should always include a number before and after a decimal point to make it clear the intent is to create a decimal number.
12
13## Rule Details
14
15This rule is aimed at eliminating floating decimal points and will warn whenever a numeric value has a decimal point but is missing a number either before or after it.
16
17Examples of **incorrect** code for this rule:
18
19```js
20/*eslint no-floating-decimal: "error"*/
21
22var num = .5;
23var num = 2.;
24var num = -.7;
25```
26
27Examples of **correct** code for this rule:
28
29```js
30/*eslint no-floating-decimal: "error"*/
31
32var num = 0.5;
33var num = 2.0;
34var num = -0.7;
35```
36
37## When Not To Use It
38
39If you aren't concerned about misinterpreting floating decimal point values, then you can safely turn this rule off.
40
41## Compatibility
42
43* **JSHint**: W008, W047