mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:49:19 +08:00
fix: 统一表格数字单元格显示逻辑,0值显示为数字而非'-'
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 概览表单元格:0 正常展示;仅 null / undefined / 非有限数显示为 '-'
|
||||
*/
|
||||
export function formatNumberCell(
|
||||
value: number | null | undefined,
|
||||
format: (n: number) => string,
|
||||
): string {
|
||||
if (value === null || value === undefined) return '-';
|
||||
const n = Number(value);
|
||||
if (!Number.isFinite(n)) return '-';
|
||||
return format(n);
|
||||
}
|
||||
|
||||
export function formatIntCell(
|
||||
value: number | null | undefined,
|
||||
locale = 'zh-CN',
|
||||
): string {
|
||||
if (value === null || value === undefined) return '-';
|
||||
const n = Number(value);
|
||||
if (!Number.isFinite(n)) return '-';
|
||||
return Math.trunc(n).toLocaleString(locale);
|
||||
}
|
||||
Reference in New Issue
Block a user