UNPKG

1.07 kBMarkdownView Raw
1# floating
2
3```js
4// usages
5chance.floating()
6chance.floating({ fixed: 7 })
7chance.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
11Return a random floating point number.
12
13```js
14chance.floating();
15=> -211920142886.5024
16```
17
18By default it will return a fixed number of at most 4 digits after the decimal.
19
20Note: *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
22the decimal. So if random chance comes back with `82383854.2000` then
23`82383854.2` is what will be returned.
24
25To retrieve a set number of fixed digits after the decimal, provide it as an option.
26
27```js
28chance.floating({ fixed: 7 });
29=> -749512327.7447168
30```
31
32As with other number functions, can include a min and/or max.
33
34```js
35chance.floating({ min: 0, max: 100 });
36=> 31.9021
37```
38
39Or combine them.
40
41```js
42chance.floating({ min: 0, max: 100, fixed: 8 });
43=> 45.92367599
44```