mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 08:29:19 +08:00
23 lines
630 B
TypeScript
23 lines
630 B
TypeScript
/**
|
|
* 概览表单元格: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);
|
|
}
|