상세 컨텐츠

본문 제목

javascript format string

카테고리 없음

by TISTORY 2014. 8. 19. 15:34

본문

http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript


Number.prototype.format = function(n, x) {
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\.' : '$') + ')';
return this.toFixed(Math.max(0, ~~n)).replace(new RegExp(re, 'g'), '$&,');
};