Returns a single random floating-point number, by default between 0.0 and 1.0. To change the range, pass a min and max value. To limit the number of decimal places, pass a multipleOf or fractionDigits parameter.
Optionaloptions: number | {}Upper bound or options object.
faker.number.float() // 0.5688541042618454
faker.number.float(3) // 2.367973240558058
faker.number.float({ max: 100 }) // 17.3687307164073
faker.number.float({ min: 20, max: 30 }) // 23.94764115102589
faker.number.float({ multipleOf: 0.25, min: 0, max:10 }) // 7.75
faker.number.float({ fractionDigits: 1 }) // 0.9
faker.number.float({ min: 10, max: 100, multipleOf: 0.02 }) // 35.42
faker.number.float({ min: 10, max: 100, fractionDigits: 3 }) // 65.716
faker.number.float({ min: 10, max: 100, multipleOf: 0.001 }) // 65.716 - same as above
Returns 0 instead of the given number depending on the chance passed (0.05 by default).
This is useful to avoid too many empty nodes without having to increase the max a lot.
You can pass chance 0 to always return the given number.