-
Notifications
You must be signed in to change notification settings - Fork 99
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
Property 'Values' in conflict #96
Comments
Something's broken about multiple thumbs and decimals. |
Any news on this issue? |
I can say that this is due to floating point arithmetic in JavaScript. Let's say, my config is like this {
min: 97,
max: 108,
step: 0.1,
values: [98.6],
} During the calculation at Lines 91 to 97 in 57345c3
It becomes Lines 17 to 20 in 57345c3
const res = (max - min) / step;
// (98.6 - 97) / 0.1
// 15.999999999999943
return parseInt(res.toString(), 10) === res;
// 15 === 15.999999999999943
// false One possible solution is to take a Like const multiplier = 10 ** precision;
const normalizedMax = Math.round(max * multiplier);
const normalizedMin = Math.round(min * multiplier);
const normalizedStep = Math.round(step * multiplier);
const res = (max - min) / step;
// (986 - 970) / 1
// 16
return parseInt(res.toString(), 10) === res;
// 16 === 16
// true I have forked this library and made such changes. I cannot think of any other method where I can reliably extract number of decimal points from given values. |
Hey,
I am using react-range with a min / max of 0 and 1 and a step of 0.001. the values I am sending is within an array.
[0.66, 0.947]
I seem to get the warning appear on component load. Am I missing something as this seems in range to me..
Thanks in advance
The text was updated successfully, but these errors were encountered: