修复格式化数字问题

sheep/hooks/useGoods.js格式化数字 
情况三时没有对数字格式

Signed-off-by: DH <ji534@outlook.com>
pull/39/head
DH 2024-01-29 01:34:51 +00:00 committed by Gitee
parent 829bea3861
commit 87a6b962e7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 4 additions and 2 deletions

View File

@ -55,8 +55,10 @@ export function formatNum(prefix, type, num) {
// 情况三:大于 10除第一位外其它位都显示为0
// 例如100 - 199 显示为 100+
// 9000 - 9999 显示为 9000+
let pow = Math.pow(10, `${num}`.length - 1);
return `${prefix}${Math.round((num / pow) * pow)}+`;
const numStr = num.toString();
const first = numStr[0];
const other = '0'.repeat(numStr.length - 1);
return `${prefix}${first}${other}+`;
}
// 格式化价格