fix(图表): 修复标签的小数四舍五入错误

This commit is contained in:
wisonic
2025-03-05 19:02:36 +08:00
committed by wisonic-s
parent 3a1a6572db
commit 25427c5d53

View File

@@ -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)/)) {