diff --git a/leopard-web/src/pages/stock/StockDetail.tsx b/leopard-web/src/pages/stock/StockDetail.tsx index d7616b0..a7a4948 100644 --- a/leopard-web/src/pages/stock/StockDetail.tsx +++ b/leopard-web/src/pages/stock/StockDetail.tsx @@ -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 => {