Skip to content Skip to sidebar Skip to footer

Jquery Ui Slider Incorrect Max Value

I am initializing a jquery ui slider that has for example a value of .01, a min of .01, and a max of 5000. My issue is that the max is stopping at 4999.990000000001. Can you see wh

Solution 1:

It's a rounding error related to the float values. The easiest way to fix it would to use integers instead:

$( "#sliderModal" ).slider({
    value:r.min_price,
    min: r.min_price,
    max: r.max_price,
    step:1,
    slide: function( event, ui ) {
        $( "#amountModal" ).val(ui.value*100);
    }
});

Notice that I've removed all the /100 operations and multiplied the value by 100.

This assumes that the value is not being displayed as a number - if it is, you're going to get the number multiplied by 100 instead of the nice, neat two-decimal-place number you're looking for.

Solution 2:

A quick fix - floating numbers

in jquery-ui.js and _calculateNewMax function, change the

Math.floor(..

to

Math.round(..

So, if there is

aboveMin = Math.floor((+(max-min).toFixed(this._precision()))/step)*step;

to

aboveMin = Math.round((+(max-min).toFixed(this._precision()))/step)*step;

Note*: you need to edit and link the modded js file localy.

Note**: Check the link to point on jquery-ui.js and not jquery-ui.min.js

checked on v1.11.4

Hope it helps,

giannisepp

Post a Comment for "Jquery Ui Slider Incorrect Max Value"