|
@@ -5,20 +5,18 @@ export const getOperationalPrecision = (num1, num2) => {
|
|
|
}
|
|
|
|
|
|
// 金额转大写
|
|
|
-export const dealBigMoney = (n) =>{
|
|
|
- if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
|
|
|
- return "数据非法";
|
|
|
- let unit = "千百拾亿千百拾万千百拾元角分", str = "";
|
|
|
- n += "00";
|
|
|
- let p = n.indexOf('.');
|
|
|
- if (p >= 0){
|
|
|
- n = n.substring(0, p) + n.substr(p+1, 2);
|
|
|
- unit = unit.substr(unit.length - n.length);
|
|
|
+export const dealBigMoney = (n) => {
|
|
|
+ if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n)) { return '数据非法' }
|
|
|
+ let unit = '千百拾亿千百拾万千百拾元角分'; let str = ''
|
|
|
+ n += '00'
|
|
|
+ const p = n.indexOf('.')
|
|
|
+ if (p >= 0) {
|
|
|
+ n = n.substring(0, p) + n.substr(p + 1, 2)
|
|
|
+ unit = unit.substr(unit.length - n.length)
|
|
|
}
|
|
|
-
|
|
|
- for (var i=0; i < n.length; i++)
|
|
|
- str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
|
|
|
- return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
|
|
|
+
|
|
|
+ for (var i = 0; i < n.length; i++) { str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i) }
|
|
|
+ return str.replace(/零(千|百|拾|角)/g, '零').replace(/(零)+/g, '零').replace(/零(万|亿|元)/g, '$1').replace(/(亿)万|壹(拾)/g, '$1$2').replace(/^元零?|零分/g, '').replace(/元$/g, '元整')
|
|
|
}
|
|
|
|
|
|
export const forEach = (arr, fn) => {
|
|
@@ -233,13 +231,13 @@ export const numberToFixed = function (val, num) {
|
|
|
return _value
|
|
|
}
|
|
|
export const toFixedDecimal = function (num, decimal) {
|
|
|
- let newNum= null;
|
|
|
- let patrn=/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;
|
|
|
- if(!patrn.exec(num)){
|
|
|
- newNum=parseFloat(num).toFixed(decimal)
|
|
|
- }else{
|
|
|
- newNum =num
|
|
|
- }
|
|
|
+ let newNum = null
|
|
|
+ const patrn = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi
|
|
|
+ if (!patrn.exec(num)) {
|
|
|
+ newNum = parseFloat(num).toFixed(decimal)
|
|
|
+ } else {
|
|
|
+ newNum = num
|
|
|
+ }
|
|
|
return newNum
|
|
|
}
|
|
|
// 保留decimal位小数(不四舍五入) num 数值,decimal要保留的小数位数
|
|
@@ -258,8 +256,8 @@ export const toThousands = (num, decimal) => {
|
|
|
if (num == undefined) {
|
|
|
return '--'
|
|
|
}
|
|
|
- num = formatDecimal(num, decimal || decimal==0 ? decimal : 2)
|
|
|
- return num.toString().replace(/\d+/, function (n) { // 先提取整数部分
|
|
|
+ num = formatDecimal(num, decimal || decimal == 0 ? decimal : 2)
|
|
|
+ return '¥' + num.toString().replace(/\d+/, function (n) { // 先提取整数部分
|
|
|
return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) {
|
|
|
return $1 + ','
|
|
|
})
|
|
@@ -483,4 +481,3 @@ export const checkIdNumberValid = (tex) => {
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
-
|