Skip to content

Commit

Permalink
Fix rounding bug for number with exponential part
Browse files Browse the repository at this point in the history
When a number presents an exponential part (scientific representation,
ie. 5e+3) an additional “e+” string is appended to the number to
perform the `toFixedFix` function. It causes the `Math.round` method to
return a `NaN` value.
  • Loading branch information
indrimuska committed May 12, 2015
1 parent a952fe9 commit c2740f9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion jquery.number.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@
var n = !isFinite(+number) ? 0 : +number,
s = '',
toFixedFix = function (n, decimals) {
return '' + (+(Math.round(n + 'e+' + decimals) + 'e-' + decimals));
return '' + (+(Math.round(('' + n).indexOf('e') > 0 ? n : n + 'e+' + decimals) + 'e-' + decimals));
};

// Fix for IE parseFloat(0.55).toFixed(0) = 0;
Expand Down
2 changes: 1 addition & 1 deletion jquery.number.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2740f9

Please sign in to comment.