From e68f472b866b80e863c55f8dfa1f123ffa692002 Mon Sep 17 00:00:00 2001 From: Kitten9533 <1173860556@qq.com> Date: Mon, 4 Jun 2018 16:28:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DdigitUppercase(2.01)=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=B8=BA=E8=B4=B0=E5=85=83=E6=95=B4=E7=9A=84=EF=BC=8C?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=A4=A7=E5=86=99=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E2=80=9C=E4=B8=87=E4=BA=BF=E2=80=9D=20(#1589)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix digitUppercase (2.01) error returned as 贰元整 Signed-off-by: jiangjiahao <1173860556@qq.com> --- src/utils/utils.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 0dad8d87..37b6eca6 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -70,14 +70,23 @@ export function getPlainNode(nodeList, parentPath = '') { return arr; } +function accMul(arg1, arg2) { + let m = 0; + const s1 = arg1.toString(); + const s2 = arg2.toString(); + m += s1.split(".").length > 1 ? s1.split(".")[1].length : 0; + m += s2.split(".").length > 1 ? s2.split(".")[1].length : 0; + return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / 10 ** m; +} + export function digitUppercase(n) { const fraction = ['角', '分']; const digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']; - const unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']]; + const unit = [['元', '万', '亿'],['', '拾', '佰', '仟', '万']]; let num = Math.abs(n); let s = ''; fraction.forEach((item, index) => { - s += (digit[Math.floor(num * 10 * 10 ** index) % 10] + item).replace(/零./, ''); + s += (digit[Math.floor(accMul(num, 10 * 10 ** index)) % 10] + item).replace(/零./, ''); }); s = s || '整'; num = Math.floor(num); -- GitLab