Skip to content

Commit 1ce0fff

Browse files
committed
Use _round for very small numbers with toExponential
1 parent 4012562 commit 1ce0fff

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

highcharts-regression.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
return 0;
382382
});
383383

384-
var string = 'y = ' + A.toExponential(decimalPlaces) + 'x^' + _round(B, decimalPlaces);
384+
var string = 'y = ' + _round(A, decimalPlaces) + 'x^' + _round(B, decimalPlaces);
385385

386386
return {equation: [A, B], points: results, string: string};
387387
}
@@ -654,6 +654,10 @@
654654
}
655655

656656
function _round(number, decimalPlaces) {
657+
// Smaller than 0.xxxx (decimalPlaces), use scientific notation
658+
if (number < Math.pow(10, -decimalPlaces)) {
659+
return number.toExponential(decimalPlaces);
660+
}
657661
var decimalFactor = Math.pow(10, decimalPlaces);
658662
return Math.round(number * decimalFactor) / decimalFactor;
659663
}

0 commit comments

Comments
 (0)