Skip to content
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

Multiple doesn't handle floats correctly #46

Closed
LinusU opened this issue Sep 9, 2018 · 5 comments
Closed

Multiple doesn't handle floats correctly #46

LinusU opened this issue Sep 9, 2018 · 5 comments

Comments

@LinusU
Copy link

LinusU commented Sep 9, 2018

e.g.

const iz = require('iz')
const validators = require('iz/lib/validators')

iz.register(validators)

console.log(iz(2.3).multiple(0.01).valid)

logs false instead of true.

This is because 2.3 % 0.01 is 0.009999999999999775 in JavaScript 🤦‍♂️

@parris
Copy link
Owner

parris commented Sep 11, 2018

Ahhh fun - sorry about that. Is there a validator you added manually as a workaround? Did you come up with a solution? Should we add that back into iz?

@LinusU
Copy link
Author

LinusU commented Sep 11, 2018

I started exploring this due to mafintosh/is-my-json-valid#172. It seems like the implementation in is-my-json-valid works:

https://github.com/mafintosh/is-my-json-valid/blob/dcea5be83be29ea444c81bd83e7aef732a11c003/index.js#L100-L110

@parris
Copy link
Owner

parris commented Oct 31, 2019

@LinusU do I have permission to use that code in iz - with some tweaks and tests? Planning on making a new validator for multiples of floats.

@parris
Copy link
Owner

parris commented Nov 1, 2019

I'm going to assume the answer is yes :). Let me know if the implementation needs to be different.

@parris parris closed this as completed Nov 1, 2019
@LinusU
Copy link
Author

LinusU commented Nov 1, 2019

Absolutely, the code is MIT licensed!

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

No branches or pull requests

2 participants