function format(str){ temp1 = ''; temp2 = str.match(/...$/); while(temp2 != null){ temp1 = temp2 + ','+temp1; str = str.replace(/...$/,''); temp2 = str.match(/...$/); } temp1 = (str!='') ? str + ',' + temp1 : temp1; temp1 = temp1.replace(/.$/,""); return temp1; } //正規表現を駆使した方法 function format2(str){ var temp1 = str.match(/./g).reverse().join(""); temp1 = temp1.replace(/(\d{3})/g,"$1,"); temp1 = temp1.match(/./g).reverse().join("").replace(/^,/,""); return temp1; }