Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
fix: floation point rounding issue
Browse files Browse the repository at this point in the history
Change `getValueFromPosition` value calculation.
The `+ this.min` needs to be outside, otherwise it gets the wrong
answer unless `this.min` is divisible by this.step.
Big ups to @jpmckinney

Closes issue #50, #91
  • Loading branch information
andreruffert committed Sep 28, 2014
1 parent 8df30fb commit 94c5f74
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
Plugin.prototype.getValueFromPosition = function(pos) {
var percentage, value;
percentage = ((pos) / (this.maxHandleX || 1));
value = this.step * Math.ceil((((percentage) * (this.max - this.min)) + this.min) / this.step);
value = this.step * Math.round(percentage * (this.max - this.min) / this.step) + this.min;
return Number((value).toFixed(2));
};

Expand Down
2 changes: 1 addition & 1 deletion dist/rangeslider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
Plugin.prototype.getValueFromPosition = function(pos) {
var percentage, value;
percentage = ((pos) / (this.maxHandleX || 1));
value = this.step * Math.ceil((((percentage) * (this.max - this.min)) + this.min) / this.step);
value = this.step * Math.round(percentage * (this.max - this.min) / this.step) + this.min;
return Number((value).toFixed(2));
};

Expand Down

0 comments on commit 94c5f74

Please sign in to comment.