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

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

No files matched your search

+15 -1
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)
}