diff --git a/Utilities.js b/Utilities.js index fae5f22a5..7878498c3 100644 --- a/Utilities.js +++ b/Utilities.js @@ -25,11 +25,12 @@ function drawContainerBackground (container, color, opacity, fitFunction) { function dynamicDecimals (value) { let decimals = 2 if (value < 1) { decimals = 4 } - if (Math.trunc(value * 100) < 1) { decimals = 6 } - if (Math.trunc(value * 10000) < 1) { decimals = 8 } - if (Math.trunc(value * 1000000) < 1) { decimals = 10 } - if (Math.trunc(value * 100000000) < 1) { decimals = 12 } - if (Math.trunc(value * 10000000000) < 1) { decimals = 0 } + if (Math.abs(Math.trunc(value * 100)) < 1) { decimals = 6 } + if (Math.abs(Math.trunc(value * 10000)) < 1) { decimals = 8 } + if (Math.abs(Math.trunc(value * 1000000)) < 1) { decimals = 10 } + if (Math.abs(Math.trunc(value * 100000000)) < 1) { decimals = 12 } + if (Math.abs(Math.trunc(value * 10000000000)) < 1) { value = 0; decimals = 0 } + if (Math.trunc(value) === value) { decimals = 0 } let returnValue = Number(value).toFixed(decimals) return returnValue }