/*
将数字转换成千分位展示
number:传入的数字。必选
places:小数点的位数。可选,默认为两位小数
symbol:数字最后的符号 。可选,默认为美元字符“¥”
thousand:千分位分隔符。可选,默认为“,”
decimal:小数位分隔符。可选,默认为“.”
*/
function formatMoney(number, places, symbol, thousand, decimal) {
number = number || 0;
places = !isNaN(places = Math.abs(places)) ? places : 2;
symbol = symbol !== undefined ? symbol : "$";
thousand = thousand || ",";
decimal = decimal || ".";
var negative = number < 0 ? "-" : "",
i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(d{3})(?=d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "")+symbol;
}
/*
将千分位转换成数字展示。
number:传入的千分位展示字符串。必选
thousand:千分位分隔符。必选
isSymbol:千分位展示字符串末尾的标识。可选,传入后,传入的千分位字符串长度减去isSymbol的长度
*/
function toNumber(number,thousand,isSymbol){
if(isSymbol){
var len =number.length - isSymbol.length;
number = number.substring(0,number.len);
}
number = number.split(thousand).join("");
return number;
}