Browse Source

修复digitUppercase(2.01)返回为贰元整的,数字大写增加了“万亿” (#1589)

Fix digitUppercase (2.01) error returned as 贰元整

Signed-off-by: jiangjiahao <1173860556@qq.com>
pull/1599/head
Kitten9533 8 years ago
committed by 陈帅
parent
commit
e68f472b86
  1. 13
      src/utils/utils.js

13
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);

Loading…
Cancel
Save