edgji edgji - 3 months ago 8
jQuery Question

jquery ui slider value avoid truncating to 5 decimal places

I'm using jquery slider with 10 decimal place steps to make some calculations easier. I was having issues with some of the calculations not adding up and I just found out that slider values were being truncated to 5 decimal places for values of 1/3 which would be .33333333333.

Is there a way to force jquery ui slider's value method to not truncate values or to use a set amount of decimal places when storing slider values?

Answer

There is no way to do this via the jqueryui API.

However, there is an explicit rounding to 5 digits going on the _trimValueAlign function on the slider class.

In v1.9.2 (current stable release) this is on line 11530 of the non-minified script. Here'sthe code snippet.

// Since JavaScript has problems with large floats, round
// the final value to 5 digits after the decimal point (see #4124)
return parseFloat( alignValue.toFixed(5) );

you could consider changing this directly to the 10 that you require and do a lot of testing.

Also consider raising a ticket or asking for this to be a looked at by the jqueryui community, perhaps its an outdated fix.(?) The quoted issue speaks of Firefox 3.x and Windows XP http://bugs.jqueryui.com/ticket/4124

Comments