价格小数处理,小数点后面字符多余3个时候,取一个

function datadel(e){
var arr = String(e).split(".");
(arr[arr.length - 1]).length>=3?
e= e.toFixed(1):e=e;
console.log(e);
return e;
}

 

var original = datadel(parseFloat(data[i].original_price*0.01));

 

 

 

function datadel(e){
var str = String(e.toFixed(2));
while(str[str.length-1]=='0'){
str=str.substring(0,str.length-1);
}
if(str[str.length-1]=='.'){
str=str.substring(0,str.length-1);
}
return str;
}

posted @ 2017-03-10 10:46  winyh  阅读(199)  评论(0编辑  收藏  举报