Minus zero bug
by Black Label
HTML
<script src="https://code.highcharts.com/highcharts.src.js"></script>
<div id="container"></div>
CSS
#container {
height: 300px;
max-width: 400px;
}
JavaScript
(function(H) {
const { pick, isNumber, defaultOptions, pInt } = H;
H.numberFormat = function (number, decimals, decimalPoint, thousandsSep) {
number = +number || 0;
decimals = +decimals;
let ret, fractionDigits;
const lang = defaultOptions.lang, origDec = (number.toString().split('.')[1] || '').split('e')[0].length, exponent = number.toString().split('e'), firstDecimals = decimals;
if (decimals === -1) {
// Preserve decimals. Not huge numbers (#3793).
decimals = Math.min(origDec, 20);
}
else if (!isNumber(decimals)) {
decimals = 2;
}
else if (decimals && exponent[1] && exponent[1] < 0) {
// Expose decimals from exponential notation (#7042)
fractionDigits = decimals + +exponent[1];
if (fractionDigits >= 0) {
// remove too small part of the number while keeping the notation
exponent[0] = (+exponent[0]).toExponential(fractionDigits)
.split('e')[0];
decimals = fractionDigits;
}
else {
// fractionDigits < 0
exponent[0] = exponent[0].split('.')[0] || 0;
if (decimals < 20) {
// use number instead of exponential notation (#7405)
number = (exponent[0] * Math.pow(10, exponent[1]))
.toFixed(decimals);
}
else {
// or zero
number = 0;
}
exponent[1] = 0;
}
}
// Add another decimal to avoid rounding errors of float numbers. (#4573)
// Then use toFixed to handle rounding.
const roundedNumber = (Math.abs(exponent[1] ? exponent[0] : number) +
Math.pow(10, -Math.max(decimals, origDec) - 1)).toFixed(decimals);
// A string containing the positive integer component of the number
const strinteger = String(pInt(roundedNumber));
// Leftover after grouping into thousands. Can be 0, 1 or 2.
const thousands = strinteger.length > 3 ? strinteger.length % 3 : 0;
// Language
decimalPoint =...