1 | # floating
|
2 |
|
3 | ```js
|
4 | // usages
|
5 | chance.floating()
|
6 | chance.floating({ fixed: 7 })
|
7 | chance.floating({ min: 0, max: 100 })
|
8 | ```
|
9 | <p class="pullquote">I wanted to use float or double as the method name but both are JS reserved words even though they aren't really used...</p>
|
10 |
|
11 | Return a random floating point number.
|
12 |
|
13 | ```js
|
14 | chance.floating();
|
15 | => -211920142886.5024
|
16 | ```
|
17 |
|
18 | By default it will return a fixed number of at most 4 digits after the decimal.
|
19 |
|
20 | Note: *at most* 4 digits. This because, unless we returned trailing zeroes
|
21 | (which aren't allowed on the JavaScript float) we can't guarantee 4 digits after
|
22 | the decimal. So if random chance comes back with `82383854.2000` then
|
23 | `82383854.2` is what will be returned.
|
24 |
|
25 | To retrieve a set number of fixed digits after the decimal, provide it as an option.
|
26 |
|
27 | ```js
|
28 | chance.floating({ fixed: 7 });
|
29 | => -749512327.7447168
|
30 | ```
|
31 |
|
32 | As with other number functions, can include a min and/or max.
|
33 |
|
34 | ```js
|
35 | chance.floating({ min: 0, max: 100 });
|
36 | => 31.9021
|
37 | ```
|
38 |
|
39 | Or combine them.
|
40 |
|
41 | ```js
|
42 | chance.floating({ min: 0, max: 100, fixed: 8 });
|
43 | => 45.92367599
|
44 | ```
|