CRM:code review【客户统计】的代码实现

This commit is contained in:
YunaiV
2024-03-30 11:02:29 +08:00
parent b51397fe19
commit 1b7d604858
4 changed files with 45 additions and 28 deletions

View File

@ -329,10 +329,11 @@ const ERP_PRICE_DIGIT = 2
* 例如说:库存数量
*
* @param num 数量
* @package digit 保留的小数位数
* @return 格式化后的数量
*/
export const erpNumberFormatter = (num: number | string | undefined, digit: number) => {
if (num === null) {
if (num == null) {
return ''
}
if (typeof num === 'string') {
@ -404,3 +405,16 @@ export const erpPriceMultiply = (price: number, count: number) => {
}
return parseFloat((price * count).toFixed(ERP_PRICE_DIGIT))
}
/**
* 【ERP】百分比计算四舍五入保留两位小数
*
* 如果 total 为 0则返回 0
*
* @param value 当前值
* @param total 总值
*/
export const erpCalculatePercentage = (value: number, total: number) => {
if (total === 0) return 0
return ((value / total) * 100).toFixed(2)
}