diff --git a/core/core-frontend/src/views/chart/components/js/formatter.ts b/core/core-frontend/src/views/chart/components/js/formatter.ts index a297fbb86d..480750eaba 100644 --- a/core/core-frontend/src/views/chart/components/js/formatter.ts +++ b/core/core-frontend/src/views/chart/components/js/formatter.ts @@ -51,13 +51,27 @@ function transUnit(value, formatter) { } function transDecimal(value, formatter) { - const resultV = value.toFixed(formatter.decimalCount) + const resultV = retain(value, formatter.decimalCount) as string if (Object.is(parseFloat(resultV), -0)) { return resultV.slice(1) } return resultV } +function retain(value, n) { + if (!n) return Math.round(value) + const tran = Math.round(value * Math.pow(10, n)) / Math.pow(10, n) + let tranV = tran.toString() + const newVal = tranV.indexOf('.') + if (newVal < 0) { + tranV += '.' + } + for (let i = tranV.length - tranV.indexOf('.'); i <= n; i++) { + tranV += '0' + } + return tranV +} + function transSeparatorAndSuffix(value, formatter) { let str = value + '' if (str.match(/^(\d)(\.\d)?e-(\d)/)) {