金额转千分位 /** * 金额转千分位 * @param price * @returns string */function toThousands(price){ var digit = 2;//保留小数位数 price = parseFloat((price + "").replace(/[^\d\.-]/g, "")).toFixed(digit) + ""; var leftPart = pri
/** * 金额转千分位 * @param price * @returns string */ function toThousands(price) { var digit = 2;//保留小数位数 price = parseFloat((price + "").replace(/[^\d\.-]/g, "")).toFixed(digit) + ""; var leftPart = price.split(".")[0].split("").reverse();//左侧 var rightPart = price.split(".")[1];//右侧 var thousandsResult = ""; for(var i = 0; i < leftPart.length; i ++ ) { thousandsResult += leftPart[i] + ((i + 1) % 3 == 0 && (i + 1) != leftPart.length ? "," : "");//千分标识 } return thousandsResult.split("").reverse().join("") + "." + rightPart; //拼接 }