Faker.js: [Feature Request] add support to generate random floating point numbers

Created on 22 Sep 2019  路  4Comments  路  Source: Marak/faker.js

Hi there, would it be possible to add support to generate random floating-point numbers?

I will suggest modifying the options parameter passed when faker.random.number is called to support floating point numbers. Thanks!

All 4 comments

+1 on this

In the meantime, I'm using this alternative:

Precision as a floating point
random.number({min: 60, max: 65, precision: 2 ** -2}) // --> 62.625
(note: make sure you use something which is nice in binary [for your precision] to avoid super long floating points (see: https://0.30000000000000004.com/) or do a Math.round at the end

Maybe wouldn't it be better to just use random.float that is already supported?

This feature was added as random.float in Aug 2017 https://github.com/Marak/faker.js/commit/56aa8121f254482ae2f200605402c9d4eb917abe, however, there hasn't been a published version since then.

Resolved.

Was this page helpful?
0 / 5 - 0 ratings