faker
faker copied to clipboard
datatype.float does not return a float with given precision
Describe the bug
The code indicates that float can take a number that will be used as precision value.
But it returns always a integer number when using typoef options === 'number'
Reproduction
faker.seed(42)
faker.datatype.float(6) === 37452
Additional Info
I found this bug while rewriting the datatype tests in #344
This behavior might be intentional:
faker.datatype.number(1000) // 64000
faker.datatype.float(1000) // 64000
After further investigation, I think you're right @ST-DDT - it looks like it's a feature, not a bug. The precision option is set, but the name precision might be a little unfortunate here. It does not refer only to significant decimal digits, as this unit test exposes.
faker.datatype.number(1000) // 64000 faker.datatype.float(1000) // 64000
Are you 100% sure about the faker.datatype.number(1000) output? I think this should be random number form [0;1000]?
faker.seed(42)
faker.datatype.number(1000) // 374
faker.seed(42)
faker.datatype.float(1000) // 37000
Are you 100% sure about the
faker.datatype.number(1000)output?
I meant faker.datatype.number({ precision: 1000 })); // 37000.
IMO precision is a good word for it (or at least I cannot think of a better one right now).
IMO precision is a good word for it (or at least I cannot think of a better one right now).
It resembles precision if represented with 10^n, but in reality it can take any Number. What is this number in those cases, then? How would you explain what's going on? I find it hard to put it in simple words and the term "precision" is misused imho :) I also find it very weird how the precision influence the outcome:
faker.seed(42);
faker.datatype.float({ precision: 1 } // 37454
faker.seed(42);
faker.datatype.float({ precision: 9 } // 37449
faker.seed(42);
faker.datatype.float({ precision: 10 } // 37450
faker.seed(42);
faker.datatype.float({ precision: 11 } // 37455
Correct me if I'm wrong, but this has little in common to precision as typically the mathematical precision is represented as integer, and refers to the number of significant decimal digits.
I think it should work like Number.toPrecision, but in decimal notation:
I doubt it is expected of that Issue to create that massive breaking change right now, is it?
It's not my call, I'm happy to go back and provide the PR anytime the expected behavior is established.
I doubt it is expected of that Issue to create that massive breaking change right now, is it?
Yes, you are right. We have to put more thoughts into this.
Superseded by https://github.com/faker-js/faker/issues/1596
- #1596