//分换算元export function toMoney(num: any) { num = parseFloat(num) / 100; num += ''; num = num.replace(/[^0-9|\.]/g, ''); if (/^0+/) { num = num.replace(/^0+/, ''); } if (!/\./.test(num)) { num += '.00'; } if (/^\./.test(num)) { num = '0' + num; } num += '00'; num = num.match(/\d+\.\d{2}/)[0]; return num;}
// 格式化 金额 获取整数部分 const getInteger = (val: number) => { const num = val / 100; const result = Number(num.toString().match(/^\d+(?:\.\d{0,2})?/)); let s = result.toString(); let rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; } while (s.length <= rs + 2) { s += '0'; } let htmlStr = s.split('.')[0]; return htmlStr; } // 格式化 金额 获取小数部分 const getDecimal = (val: number) => { const num = val / 100; const result = Number(num.toString().match(/^\d+(?:\.\d{0,2})?/)); let s = result.toString(); let rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; } while (s.length <= rs + 2) { s += '0'; } let htmlStr = s.split('.')[1]; return htmlStr; }