From: msrocka Date: Mon, 25 Aug 2014 11:29:22 +0000 (+0200) Subject: fix #570: getDecimalPlaces throws error X-Git-Tag: v2.0-alpha~52^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F575%2Fhead;p=thirdparty%2FChart.js.git fix #570: getDecimalPlaces throws error --- diff --git a/src/Chart.Core.js b/src/Chart.Core.js index 03b99b45a..32fcdeee4 100755 --- a/src/Chart.Core.js +++ b/src/Chart.Core.js @@ -306,7 +306,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;