memo.xight.org

日々のメモ

JavaScript で数値を3桁区切り

function toReadableNumber(str){
	var ret = Math.floor(str).toString();
	ret = ret.match(/./g).reverse().join("");
	ret = ret.replace(/(\d{3})/g,"$1,");
	ret = ret.match(/./g).reverse().join("").replace(/^,/,"");
	return ret;
}


Reference

きんがくとかをけたくぎり
http://page.freett.com/elledia/tips/comma.html