7/17 添加公区收益
This commit is contained in:
@@ -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, ',') + ' 元';
|
||||
}
|
||||
}
|
||||
// 带货币符号(¥)版本
|
||||
|
||||
Reference in New Issue
Block a user