aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.spinner.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/jquery.ui.spinner.js')
-rw-r--r--ui/jquery.ui.spinner.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/ui/jquery.ui.spinner.js b/ui/jquery.ui.spinner.js
index fa8b065fb..ffcead73d 100644
--- a/ui/jquery.ui.spinner.js
+++ b/ui/jquery.ui.spinner.js
@@ -228,10 +228,13 @@ $.widget( "ui.spinner", {
this.counter = 1;
}
- var newVal = this.value() + step * this._increment( this.counter );
+ var newVal = this.value() + step * this._increment( this.counter ),
+ // fix precision from bad JS floating point math
+ precision = Math.max( this._precision( this.value() ),
+ this._precision( this.options.step ) );
// clamp the new value
- newVal = this._trimValue( newVal );
+ newVal = this._trimValue( newVal.toFixed( precision ) );
if ( !this.spinning || this._trigger( "spin", event, { value: newVal } ) !== false) {
this._value( newVal );
@@ -245,6 +248,12 @@ $.widget( "ui.spinner", {
1;
},
+ _precision: function( num ) {
+ var str = num.toString(),
+ decimal = str.indexOf( "." );
+ return decimal === -1 ? 0 : str.length - decimal - 1;
+ },
+
_trimValue: function( value ) {
var options = this.options;