mirror of
https://github.com/dataease/dataease.git
synced 2026-05-15 05:22:13 +08:00
fix(图表): 修复标签的小数四舍五入错误
This commit is contained in:
@@ -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)/)) {
|
||||
|
||||
Reference in New Issue
Block a user