Last active
December 15, 2015 12:38
-
-
Save jeedy/5261399 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 숫자 타입에서 쓸 수 있도록 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