Skip to content

Commit 65b0b19

Browse files
committed
Use _round for very small numbers with toExponential
1 parent 6fa3b31 commit 65b0b19

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

highcharts-regression.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
return 0;
299299
});
300300

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

303303
return {equation: [A, B], points: results, string: string};
304304
}
@@ -570,7 +570,12 @@
570570
return SE;
571571
}
572572

573+
573574
function _round(number, decimalPlaces) {
575+
// Smaller than 0.xxxx (decimalPlaces), use scientific notation
576+
if (number < Math.pow(10, -decimalPlaces)) {
577+
return number.toExponential(decimalPlaces);
578+
}
574579
var decimalFactor = Math.pow(10, decimalPlaces);
575580
return Math.round(number * decimalFactor) / decimalFactor;
576581
}

0 commit comments

Comments
 (0)