]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
fix #570: getDecimalPlaces throws error 575/head
authormsrocka <michael.srocka@gmail.com>
Mon, 25 Aug 2014 11:29:22 +0000 (13:29 +0200)
committermsrocka <michael.srocka@gmail.com>
Mon, 25 Aug 2014 11:29:22 +0000 (13:29 +0200)
src/Chart.Core.js

index 03b99b45a582e69ae57ea79f3ed3e5bbae3bb0d1..32fcdeee483b3f61b30f51952e09394ed89daad9 100755 (executable)
                },
                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;