60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
export function formatAmount(value: number | null): string {
|
|
if (value === null || Number.isNaN(value)) {
|
|
return '--'
|
|
}
|
|
|
|
return `${value.toFixed(2)}`
|
|
}
|
|
|
|
export function formatFlowAmountYi(value: number | null): string {
|
|
if (value === null || Number.isNaN(value)) {
|
|
return '--'
|
|
}
|
|
|
|
return `${value.toFixed(2)} 亿`
|
|
}
|
|
|
|
export function formatPrice(value: number | null): string {
|
|
if (value === null || Number.isNaN(value)) {
|
|
return '--'
|
|
}
|
|
|
|
return `${value.toFixed(2)}`
|
|
}
|
|
|
|
export function formatPercent(value: number | null): string {
|
|
if (value === null || Number.isNaN(value)) {
|
|
return '--'
|
|
}
|
|
|
|
return `${value.toFixed(2)}%`
|
|
}
|
|
|
|
export function formatTimestamp(value: string | null): string {
|
|
return value ?? '待更新'
|
|
}
|
|
|
|
export function formatMarketState(state: string): string {
|
|
const mapping: Record<string, string> = {
|
|
pre_open: '盘前',
|
|
trading_am: '上午交易',
|
|
midday_break: '午间休市',
|
|
trading_pm: '下午交易',
|
|
finalizing: '收盘确认中',
|
|
closed: '已收盘'
|
|
}
|
|
|
|
return mapping[state] ?? state
|
|
}
|
|
|
|
export function formatPrecision(state: string): string {
|
|
const mapping: Record<string, string> = {
|
|
realtime_exact: '实时准确值',
|
|
close_final: '收盘最终值',
|
|
historical_exact: '历史准确值',
|
|
unavailable: '当前不可用'
|
|
}
|
|
|
|
return mapping[state] ?? state
|
|
}
|