From 829bea3861e92886faf43a5452fad93546f8ee12 Mon Sep 17 00:00:00 2001 From: DH Date: Mon, 29 Jan 2024 01:24:27 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E9=94=80=E9=87=8F=E5=8F=AF=E8=83=BD=E4=BC=9A?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E4=BD=99=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DH --- sheep/hooks/useGoods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sheep/hooks/useGoods.js b/sheep/hooks/useGoods.js index 2d290aff..73893bf5 100644 --- a/sheep/hooks/useGoods.js +++ b/sheep/hooks/useGoods.js @@ -56,7 +56,7 @@ export function formatNum(prefix, type, num) { // 例如:100 - 199 显示为 100+ // 9000 - 9999 显示为 9000+ let pow = Math.pow(10, `${num}`.length - 1); - return `${prefix}${(num / pow) * pow}+`; + return `${prefix}${Math.round((num / pow) * pow)}+`; } // 格式化价格 From 87a6b962e7c45b0e3210996ca7eb9cd00562e90e Mon Sep 17 00:00:00 2001 From: DH Date: Mon, 29 Jan 2024 01:34:51 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E6=95=B0=E5=AD=97=E9=97=AE=E9=A2=98=20=20sheep/hooks/?= =?UTF-8?q?useGoods.js=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=95=B0=E5=AD=97=20?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=89=E6=97=B6=E6=B2=A1=E6=9C=89=E5=AF=B9?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DH --- sheep/hooks/useGoods.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sheep/hooks/useGoods.js b/sheep/hooks/useGoods.js index 73893bf5..c3c58fe8 100644 --- a/sheep/hooks/useGoods.js +++ b/sheep/hooks/useGoods.js @@ -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}+`; } // 格式化价格