random-decimal
Return a random decimal.
Install
$ npm install --save random-decimal
Usage
For more use-cases see the tests
var randomDecimal = ; // API// - randomDecimal([options]) // options// - min// - max// - fixed
By default it will return a fixed number of at most 4
digits after the decimal.
;// range: 0 to 9007199254740992// => 211920142886.5024
Note: at most 4
digits. This because, unless we returned trailing zeroes (which aren’t allowed on the JavaScript float) we can’t guarantee 4
digits after the decimal. So if random chance comes back with 82383854.2000
then 82383854.2
is what will be returned.
Can optionally provide min and max:
;// => 2.3785 ;// => 66.7269
Note: these min
and max
are inclusive, so they are included in the range.
To retrieve a set number of fixed digits after the decimal, provide it as an option:
;// => 749512327.7447168
Or combine them:
;// => 45.92367599
Related
- random-integral - Return a random integer.
- random-natural - Return a random natural number.
- random-floating - Return a random floating point number.
- random-index - Return a random array-like index.
- random-binary - Return a random binary number.
- random-octal - Return a random octal number.
- random-hexadecimal - Return a random hexadecimal number.
- random-unicode - Return a random unicode.
- random-bool - Return a random boolean (true/false).
- random-char - Return a random char.
Contributing
Pull requests and stars are highly welcome.
For bugs and feature requests, please create an issue.