Decimals Handling Improved
This commit is contained in:
1 parent
90300e5cdc
commit
eda2b14064
3 files changed
+16
-13
No files matched your search
@@ -110,6 +110,7 @@ function newUiObject() {
|
||||
|
||||
let errorMessage = ''
|
||||
let currentValue = 0
|
||||
let valueMinDecimals = undefined
|
||||
let currentPercentage = ''
|
||||
let currentStatus = ''
|
||||
let rightDragging = false
|
||||
@@ -745,10 +746,11 @@ function newUiObject() {
|
||||
hasError = false
|
||||
}
|
||||
|
||||
function setValue(value, counter) {
|
||||
function setValue(value, counter, minDecimals) {
|
||||
if (value !== undefined) {
|
||||
currentValue = value
|
||||
hasValue = true
|
||||
valueMinDecimals = minDecimals
|
||||
if (counter !== undefined) {
|
||||
valueCounter = counter
|
||||
} else {
|
||||
@@ -1438,7 +1440,7 @@ function newUiObject() {
|
||||
label = currentValue
|
||||
if (!isNaN(currentValue)) {
|
||||
if (currentValue.toFixed !== undefined) {
|
||||
label = dynamicDecimals(currentValue)
|
||||
label = dynamicDecimals(currentValue, valueMinDecimals)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,14 +95,14 @@ function newRecordValues() {
|
||||
pointing to the same property at the Target Node.
|
||||
*/
|
||||
if (property.config.childProperty !== undefined) {
|
||||
applyValue(targetNode[property.config.childProperty], value)
|
||||
applyValue(targetNode[property.config.childProperty], value, property.config.decimals)
|
||||
} else {
|
||||
applyValue(targetNode[property.config.codeName], value)
|
||||
applyValue(targetNode[property.config.codeName], value, property.config.decimals)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function applyValue(node, value) {
|
||||
function applyValue(node, value, minDecimals) {
|
||||
if (canvas.chartingSpace.visible !== true) { return }
|
||||
if (node === undefined) { return }
|
||||
if (node === undefined) { return }
|
||||
@@ -110,6 +110,6 @@ function newRecordValues() {
|
||||
if (node.payload.uiObject === undefined) { return }
|
||||
if (value === true) { value = 'true' }
|
||||
if (value === false) { value = 'false' }
|
||||
node.payload.uiObject.setValue(value, 1)
|
||||
node.payload.uiObject.setValue(value, 1, minDecimals)
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -7,14 +7,15 @@ 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 }
|
||||
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 }
|
||||
let decimals = 0
|
||||
if (value < 1) { decimals = 2 }
|
||||
if (Math.abs(Math.trunc(value * 100)) < 1) { decimals = 4 }
|
||||
if (Math.abs(Math.trunc(value * 10000)) < 1) { decimals = 6 }
|
||||
if (Math.abs(Math.trunc(value * 1000000)) < 1) { decimals = 8 }
|
||||
if (Math.abs(Math.trunc(value * 100000000)) < 1) { decimals = 10 }
|
||||
if (Math.abs(Math.trunc(value * 10000000000)) < 1) { value = 0; decimals = 0 }
|
||||
if (Math.trunc(value) === value) { decimals = minDecimals }
|
||||
if (decimals < minDecimals) {decimals = minDecimals}
|
||||
|
||||
let returnValue = Number(value).toFixed(decimals)
|
||||
return returnValue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user