Merge pull request #575 from msrocka/master

fix #570: getDecimalPlaces throws error
This commit is contained in:
William Entriken 2015-03-17 09:28:54 -04:00
commit 8e5f1d9667

View File

@ -332,7 +332,20 @@
},
getDecimalPlaces = helpers.getDecimalPlaces = function(num){
if (num%1!==0 && isNumber(num)){
return num.toString().split(".")[1].length;
var s = num.toString();
if(s.indexOf("e-") < 0){
// no exponent, e.g. 0.01
return s.split(".")[1].length;
}
else if(s.indexOf(".") < 0) {
// no decimal point, e.g. 1e-9
return parseInt(s.split("e-")[1]);
}
else {
// exponent and decimal point, e.g. 1.23e-9
var parts = s.split(".")[1].split("e-");
return parts[0].length + parseInt(parts[1]);
}
}
else {
return 0;