aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.spinner.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-08-12 23:11:35 -0400
committerScott González <scott.gonzalez@gmail.com>2011-08-12 23:11:35 -0400
commit257021b1af4f5414fb71ada695d86bd51bb5dc04 (patch)
tree62425f102f3599ad54ea9b22a27c0eb7a7340863 /ui/jquery.ui.spinner.js
parent6c1bf56029ab2ebe45a8a5e29de1a6d9b42c8f89 (diff)
downloadjquery-ui-257021b1af4f5414fb71ada695d86bd51bb5dc04.tar.gz
jquery-ui-257021b1af4f5414fb71ada695d86bd51bb5dc04.zip
Spinner: Fixed precision when stepping.
Thanks hughlomas
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;