Decimals Handling Improved

This commit is contained in:
Luis Fernando Molina committed 2020-08-21 17:33:27 +02:00
1 parent 90300e5cdc
commit eda2b14064
3 files changed
+16 -13

No files matched your search

+8 -7
View File
@@ -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
}