perf: 优化财务数字格式化函数
This commit is contained in:
@@ -5,13 +5,23 @@ import type {Schema} from 'amis'
|
|||||||
|
|
||||||
// 格式化财务数字显示的公共函数
|
// 格式化财务数字显示的公共函数
|
||||||
const formatFinanceNumber = (value: number): string => {
|
const formatFinanceNumber = (value: number): string => {
|
||||||
if (value >= 100000000) {
|
if (value === null || value === undefined) {
|
||||||
return (value / 100000000).toFixed(2) + '亿'
|
return '-'
|
||||||
} else if (value >= 10000) {
|
|
||||||
return (value / 10000).toFixed(2) + '万'
|
|
||||||
} else {
|
|
||||||
return value.toLocaleString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 => {
|
const financePropertyLabel = (id: string | undefined, label: string, type: string, field: string): Schema => {
|
||||||
|
|||||||
Reference in New Issue
Block a user