Search and Top Navigation
#10721 closed bug (fixed)
Opened December 09, 2014 01:57AM UTC
Closed January 12, 2015 05:21PM UTC
Last modified February 09, 2015 05:04PM UTC
Slider: Cannot reach max value with step of 0.1
Reported by: | mikedehaan | Owned by: | |
---|---|---|---|
Priority: | blocker | Milestone: | 1.11.3 |
Component: | ui.slider | Version: | 1.11.2 |
Keywords: | regression | Cc: | |
Blocked by: | Blocking: |
Description
I've created a slider with values from 50 to 60 with a 0.1 step. The lower bound works just fine, but the max value is never able to be reached via the slider.
Here's a jsfiddle example:
http://jsfiddle.net/v13t8cmj/2/
The slider in the example should go to 60, however it stops at 59.9.
Attachments (0)
Change History (9)
Changed December 09, 2014 01:51PM UTC by comment:1
keywords: | → regression |
---|---|
milestone: | none → 1.12.0 |
priority: | minor → blocker |
status: | new → open |
summary: | Unable to slide to max value when using range slider → Slider: Cannot reach max value with step of 0.1 |
Changed December 09, 2014 02:12PM UTC by comment:2
_comment0: | I assume step should be a integer than a float \ \ {{{ \ _calculateNewMax: function() { \ var remainder = ( this.options.max - this._valueMin() ) % this.options.step; \ this.max = this.options.max - remainder; \ } \ }}} \ \ reference : https://github.com/dekajp/jquery-ui/commit/8932df74a70ea2e91cd7a6eb2f3c546f7f8c7597 → 1418292613336585 |
---|
I assume step should be a integer than a float
_calculateNewMax: function() { var remainder = ( this.options.max - this._valueMin() ) % this.options.step; this.max = this.options.max - remainder; }
reference : https://github.com/dekajp/jquery-ui/commit/8932df74a70ea2e91cd7a6eb2f3c546f7f8c7597
Edit :
I think the problem is floating point calculation . in chrome devtools type this 1.005 * 100 = 100.49999999999999
Changed December 17, 2014 02:43PM UTC by comment:3
Pull request: https://github.com/jquery/jquery-ui/pull/1398
Changed January 06, 2015 05:48PM UTC by comment:4
Replying to [comment:2 dekajp]:
I think the problem is floating point calculation . in chrome devtools type this 1.005 * 100 = 100.49999999999999
You're right, that's the problem. Modulo isn't mean to be used with floats, apparently. I got around it by multiplying by 100 to get larger numbers, performing the modulo function, then dividing by 100 at the end. Plus I rounded at the end to discard excess precision.
_calculateNewMax: function () { var multiplier = 100; var remainder = ((this.options.max - this._valueMin()) * multiplier) % (this.options.step * multiplier) / multiplier; remainder = Math.round((remainder + 0.00001) * multiplier) / multiplier; // Round off excess decimals this.max = this.options.max - remainder; },
Changed January 06, 2015 06:40PM UTC by comment:5
Please look at the latest fix in the pull request.
https://github.com/jquery/jquery-ui/pull/1398#issuecomment-68391087
Replying to [comment:4 Kamilche]:
Replying to [comment:2 dekajp]: > I think the problem is floating point calculation . in chrome devtools type this 1.005 * 100 = 100.49999999999999 You're right, that's the problem. Modulo isn't mean to be used with floats, apparently. I got around it by multiplying by 100 to get larger numbers, performing the modulo function, then dividing by 100 at the end. Plus I rounded at the end to discard excess precision.> _calculateNewMax: function () { > var multiplier = 100; > var remainder = ((this.options.max - this._valueMin()) * multiplier) % (this.options.step * multiplier) / multiplier; > remainder = Math.round((remainder + 0.00001) * multiplier) / multiplier; // Round off excess decimals > this.max = this.options.max - remainder; > }, >
Changed January 12, 2015 05:21PM UTC by comment:6
resolution: | → fixed |
---|---|
status: | open → closed |
Slider: Fix max calculation, when step is float
Fixes #10721
Closes gh-1398
Changeset: ae1d6d5f90236405023964bb3061eccd6c625e39
Changed February 09, 2015 05:03PM UTC by comment:8
Slider: Fix max calculation, when step is float
Fixes #10721
Closes gh-1398
(cherry picked from commit ae1d6d5f90236405023964bb3061eccd6c625e39)
Changeset: dfa3a9f8c983f5206d49000a170b42581fcc5478
Changed February 09, 2015 05:04PM UTC by comment:9
milestone: | 1.12.0 → 1.11.3 |
---|
Confirmed that this regressed in 1.11.2.