1
0

perf: 优化财务数字格式化函数

This commit is contained in:
2025-09-12 17:57:04 +08:00
parent 5b08e9cc8a
commit acab6978d4

View File

@@ -5,13 +5,23 @@ import type {Schema} from 'amis'
// 格式化财务数字显示的公共函数
const formatFinanceNumber = (value: number): string => {
if (value >= 100000000) {
return (value / 100000000).toFixed(2) + '亿'
} else if (value >= 10000) {
return (value / 10000).toFixed(2) + '万'
} else {
return value.toLocaleString()
if (value === null || value === undefined) {
return '-'
}
const isNegative = value < 0
const absoluteValue = Math.abs(value)
let formatted: string
if (absoluteValue >= 100000000) {
formatted = (absoluteValue / 100000000).toFixed(2) + '亿'
} else if (absoluteValue >= 10000) {
formatted = (absoluteValue / 10000).toFixed(2) + '万'
} else {
formatted = absoluteValue.toLocaleString()
}
return isNegative ? `-${formatted}` : formatted
}
const financePropertyLabel = (id: string | undefined, label: string, type: string, field: string): Schema => {