Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions iron-range-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@
}

var numSteps = Math.round((value - this.min) / this.step);
if (this.step < 1) {
var stepStr = this.step.toString();
var stepPointAt = stepStr.indexOf('.');
if (stepPointAt != -1) {
/**
* For small values of this.step, if we calculate the step using
* For non-integer values of this.step, if we calculate the step using
* `Math.round(value / step) * step` we may hit a precision point issue
* eg. 0.1 * 0.2 = 0.020000000000000004
* http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
*
* as a work around we can divide by the reciprocal of `step`
* as a work around we can round with the decimal precision of `step`
*/
return numSteps / (1 / this.step) + this.min;
var precision = Math.pow(10, stepStr.length - stepPointAt - 1);
return Math.round((numSteps * this.step + this.min) * precision) / precision;
} else {
return numSteps * this.step + this.min;
}
Expand Down