//千分号金额
export function getNum(num) {
return (num || 0).toString().replace(/\d+/, function (n) {
var len = n.length;
if (len % 3 === 0) {
return n.replace(/(\d{3})/g, ',$1').slice(1);
} else {
return n.slice(0, len % 3) + n.slice(len % 3).replace(/(\d{3})/g, ',$1');
}
});
}
//保留两位小数
export function saveNumTwo(num) {
let result = parseFloat(num);
if (isNaN(result)) {
alert("传递参数错误,请检查!");
return false;
}
result = Math.round(num * 100) / 100;
let s_x = result.toString(); //将数字转换为字符串
let pos_decimal = s_x.indexOf("."); //小数点的索引值
// 当整数时,pos_decimal=-1 自动补0
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += ".";
}
// 当数字的长度< 小数点索引+2时,补0
while (s_x.length <= pos_decimal + 2) {
s_x += "0";
}
return s_x;
}
//超出位数变省略号
export function numOmit(num, len) {
if (num) {
if (num.length > len) {
num = num.substr(0, len) + '...';
return num;
} else {
return num;
}
} else {
return
}
}
文本的方法是在网上查找的,忘记- -原地址了