Skip to content

Instantly share code, notes, and snippets.

@jeedy
Last active December 15, 2015 12:38
Show Gist options
  • Save jeedy/5261399 to your computer and use it in GitHub Desktop.
Save jeedy/5261399 to your computer and use it in GitHub Desktop.
// 숫자 타입에서 쓸 수 있도록 currency() 함수 추가
Number.prototype.currency = function(){
if(this==0) return 0;
var reg = /(^[+-]?\d+)(\d{3})/;
var n = (this + '');
while (reg.test(n)) n = n.replace(reg, '$1' + ',' + '$2');
return n;
};
// 문자열 타입에서 쓸 수 있도록 currency() 함수 추가
String.prototype.currency = function(){
var num = this.replace(/,/gi , "");
num = parseFloat(num);
if( isNaN(num) ) return "0";
return num.currency();
};
$(document).ready(function(){
$("input.numberFormat").keyup(function(){
$(this).val($(this).val().currency());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment