7/17 添加公区收益

This commit is contained in:
Zy
2026-07-21 17:32:22 +08:00
parent 37970c547b
commit 0c4c9676b5
41 changed files with 1583 additions and 132 deletions

View File

@@ -156,9 +156,10 @@ export function toFixedMoney(num: string | number, digit = 2): number {
* 智能金额格式化(带单位:元/万元/亿元)
* 兼容数字、字符串、null、undefined
* @param {number|string} amount 金额
* @param {number} unitNumber 保留几个小数 默认 2位
* @returns {string} 格式化后带单位的金额
*/
export function formatMoneyWithUnit(amount) {
export function formatMoneyWithUnit(amount: number | string, unitNumber: number = 2): string {
// 空值处理
if (amount == null || amount === '') return '0.00 元';
@@ -170,13 +171,13 @@ export function formatMoneyWithUnit(amount) {
if (absNum >= 100000000) {
// 亿元
return (num / 100000000).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' 亿元';
return (num / 100000000).toFixed(unitNumber).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' 亿元';
} else if (absNum >= 10000) {
// 万元
return (num / 10000).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' 万元';
return (num / 10000).toFixed(unitNumber).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' 万元';
} else {
// 元
return num.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' 元';
return num.toFixed(unitNumber).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' 元';
}
}
// 带货币符号(¥)版本