Permalink
Browse files

Merge branch '1.7.0'

  • Loading branch information...
2 parents 4d1f539 + 10269b6 commit 5b1a56f287580c26f96927fce22509e0a13ecc90 @funny-falcon committed Sep 18, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 autoNumeric.js
View
@@ -351,7 +351,10 @@
var rDec = (typeof(aPad) === 'boolean' || aPad == null) ? (aPad ? mDec : 0) : aPad * 1;
var truncateZeros = function(ivRounded) {
/** truncate not needed zeros */
- ivRounded = ivRounded.replace(new RegExp('(\\.\\d{'+rDec+'})0*$'),'$1');
+ var regex = rDec === 0 ? (/(\.[1-9]*)0*$/) :
+ rDec === 1 ? (/(\.\d[1-9]*)0*$/) :
+ new Regexp('(\\.\\d{'+rDec+'}[1-9]*)0*$');
+ ivRounded = ivRounded.replace(regex,'$1');
/** If there are no decimal places, we don't need a decimal point at the end */
if (rDec === 0) {
ivRounded = ivRounded.replace(/\.$/, '');
@@ -395,8 +398,10 @@
ivRounded += zeros;
cDec += zeros.length;
}
- } else if (cDec > rDec ) {
+ } else if (cDec > rDec) {
ivRounded = truncateZeros(ivRounded);
+ } else if (cDec === 0 && rDec === 0) {
+ ivRounded = ivRounded.replace(/\.$/, '');
}
return nSign + ivRounded;
}

0 comments on commit 5b1a56f

Please sign in to comment.