Skip to content

Use faker float when mocking numbers and int when mocking integers. #2140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SampsaKaskela opened this issue Jun 2, 2025 · 3 comments · May be fixed by #2141
Open

Use faker float when mocking numbers and int when mocking integers. #2140

SampsaKaskela opened this issue Jun 2, 2025 · 3 comments · May be fixed by #2141
Assignees
Labels
mock Related to mock generation
Milestone

Comments

@SampsaKaskela
Copy link
Contributor

At the moment when mocking any numbers they will always be integers since they are mocked with faker.number.int function. Only integers should be mocked with int and regular numbers should be mocked with float function. You can currently specify float or double as a format for number but it doesn't take into account for example minimum and maximum attributes. We could settle with some kind of default precision for floating point numbers since I don't think people want numbers with tons of decimals as default so maybe defaulting to say 2 would be reasonable. Mock options could allow setting fractionDigits option (same name as in Fakerjs 9) that allows user to set what they want as precision when mocking floats. This behavior would be overridden if user specifies multipleOf in source file since that will then determine the precision.

@melloware melloware added the mock Related to mock generation label Jun 2, 2025
@melloware melloware added this to the 8.0.0 milestone Jun 2, 2025
@melloware
Copy link
Collaborator

i assigned this to you.

@SampsaKaskela
Copy link
Contributor Author

Yeah I can tackle this. Just wondering how it will work with #2134. I probably have to wait that to be merged to avoid most of the conflicts.

@melloware
Copy link
Collaborator

OK merged your other want if you want to re update your branch and create a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mock Related to mock generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants