金额格式设置

This commit is contained in:
2025-09-09 17:03:01 +08:00
parent 460472b29a
commit d92a540786
32 changed files with 633 additions and 318 deletions

View File

@ -62,7 +62,23 @@ export const addDateRange = (params: any, dateRange: any[], propName?: string) =
}
return search;
};
// 价格格式化函数
export const formatPrice = (price, show = true) => {
if ((!show && price == 0) || price == '' || price == undefined || price == null) return '';
if (!price && price !== 0) return '0.0000';
// 转换为数字并保留四位小数
const num = Number(price);
if (isNaN(num)) return '0.0000';
const fixedNum = num.toFixed(4);
const [integer, decimal] = fixedNum.split('.');
// 千分位处理
const formattedInteger = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return `${formattedInteger}.${decimal}`;
};
// 回显数据字典
export const selectDictLabel = (datas: any, value: number | string) => {
if (value === undefined) {