1.将科学计数转为小数:
function transfor(inputNumber){
if (isNaN(inputNumber)) {
return inputNumber;
}
inputNumber = '' + inputNumber;
inputNumber = parseFloat(inputNumber);
let eformat = inputNumber.toExponential() // 转换为标准的科学计数法形式(字符串)
let tmpArray = eformat.match(/\d(?:\.(\d*))?e([+-]\d+)/) // 分离出小数值和指数值
let number = inputNumber.toFixed(Math.max(0, (tmpArray[1] || '').length - tmpArray[2]));
return number;
}
2.去掉数据末尾的无效零:
parseFloat(number)
3.将小数截取八位,不足八位显示原数据
function transfor(result){
let float = '';
let int = '';
if(result && result.indexOf('.') > -1){
int = result.split(".")[0];
let num1 = result.split(".")[1];
if(num1.length > 8){
float = num1.slice(0,8);
if(/^[0]/.test(float)){
return 0;
}else{
return int + '.' + float;
}
}else{
return result;
}
}else{
return result;
}
}