improvements in decimals
This commit is contained in:
1 parent
5ef91bbe40
commit
9e1bae5911
2 files changed
+7
-4
No files matched your search
@@ -198,8 +198,8 @@ function newSpeedometer () {
|
||||
if (isNaN(label) === false) {
|
||||
label = Number(label)
|
||||
|
||||
label = Math.trunc(label * Math.pow(10, thisObject.params.DECIMALS)) / Math.pow(10, thisObject.params.DECIMALS)
|
||||
if (label === 0) { label = label.toFixed(2) } else { label = label.toLocaleString() }
|
||||
label = dynamicDecimals(label, 2)
|
||||
if (label === 0) { label = label.toFixed(2) }
|
||||
}
|
||||
|
||||
// label = label.substring(0, 6)
|
||||
|
||||
+5
-2
@@ -22,7 +22,10 @@ function drawContainerBackground (container, color, opacity, fitFunction) {
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
|
||||
function dynamicDecimals (value) {
|
||||
function dynamicDecimals (value, minDecimals) {
|
||||
if (minDecimals === undefined) {
|
||||
minDecimals = 0
|
||||
}
|
||||
let decimals = 2
|
||||
if (value < 1) { decimals = 4 }
|
||||
if (Math.abs(Math.trunc(value * 100)) < 1) { decimals = 6 }
|
||||
@@ -30,7 +33,7 @@ function dynamicDecimals (value) {
|
||||
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 }
|
||||
if (Math.trunc(value) === value) { decimals = minDecimals }
|
||||
let returnValue = Number(value).toFixed(decimals)
|
||||
return returnValue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user