日期:2014-05-16 浏览次数:20470 次
method one:
formatMoney(parseFloat(jsonArr[i].nMarketPrice)/100, 2);
function formatMoney(num,n) {?
??? if(num && n){
??? ??? num = parseFloat(num);
??? ??? num = String(num.toFixed(n));
??? ??? var re = /(-?\d+)(\d{3})/;
??? ??? while(re.test(num)) {
??? ??? ??? num=num.replace(re,"$1,$2");
??? ??? }
??? ??? return num;
??? } else {
??? ??? return "0.00";
??? }
}
method two:
缩小100倍保留N位小数(最后一位会四舍五入)
function formatMoney(num,n) {?
??? return (num*0.01).toFixed(n);
}