Skip to content

Commit

Permalink
spinner: fixed rounding error when stepping=0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ca-Phun Ung committed Aug 19, 2008
1 parent c0147da commit 68f18e1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ui/ui.spinner.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $.widget('ui.spinner', {
_init: function() { _init: function() {


// check for decimals in steppinng and set _decimals as internal (needs cleaning up) // check for decimals in steppinng and set _decimals as internal (needs cleaning up)
var decimals = 0; this._decimals = 0;
if (this.options.stepping.toString().indexOf('.') != -1) { if (this.options.stepping.toString().indexOf('.') != -1) {
var s = this.options.stepping.toString(); var s = this.options.stepping.toString();
this._decimals = s.slice(s.indexOf('.')+1, s.length).length; this._decimals = s.slice(s.indexOf('.')+1, s.length).length;
Expand Down Expand Up @@ -267,11 +267,12 @@ $.extend($.ui.spinner, {
return (num !== Math.abs(num) ? '-' : '') + sym + this.round(Math.abs(num), 2); return (num !== Math.abs(num) ? '-' : '') + sym + this.round(Math.abs(num), 2);
}, },
round: function(num, dec) { round: function(num, dec) {
var s = Math.round(parseFloat(num)*Math.pow(10, dec)) / Math.pow(10, dec); // round off weird decimals
if (dec > 0) { if (dec > 0) {
var s = num + ((num.toString().indexOf('.') == -1) ? '.' : '') + '0000000001'; s = s + ((s.toString().indexOf('.') == -1) ? '.' : '') + '0000000001';
s = s.substr(0, s.indexOf('.')+1+dec); s = s.substr(0, s.indexOf('.')+1+dec);
} else { } else {
var s = Math.round(num); var s = Math.round(s);
} }
return s; return s;
} }
Expand Down

0 comments on commit 68f18e1

Please sign in to comment.