charFilter(rmb, bit) { var num = '0123456789.-'; var res = ''; var chrs = (rmb + '').split(''); for (var chr of chrs) { if (num.indexOf(chr) == -1) continue; res += chr; } if (!bit) bit = 2; // 默认2位小数 res = res.replace(/^-0+(\d)/,'-$1').replace(/^0+(\d)/,'$1'); // 删除开头的‘0’字符 var re = new RegExp('(^-?\\d+\\.\\d{'+bit+'})\\d*','g'); return res.replace(re,'$1'); },
数字格式字符串中剔除其他非法字符
最新推荐文章于 2022-02-26 12:22:23 发布