mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
fix #570: getDecimalPlaces throws error
This commit is contained in:
parent
0a59a3c4df
commit
5282c63ec3
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user