You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.0 KiB

  1. /**********************************************************************************************************************
  2. * 숫자에 컴마를 붙여서 리턴한다
  3. * @returns {*}
  4. *********************************************************************************************************************/
  5. Number.prototype.numberFormat = function(){
  6. if(this==0) return 0;
  7. var reg = /(^[+-]?\d+)(\d{3})/;
  8. var n = (this + '');
  9. while (reg.test(n)) n = n.replace(reg, '$1' + ',' + '$2');
  10. return n;
  11. };
  12. String.prototype.numberFormat = function() { return isNaN( parseFloat(this) ) ? "0" : (parseFloat(this)).numberFormat(); };
  13. /**********************************************************************************************************************
  14. * 컴마가 붙어있는 숫자에서 콤마를 삭제하고 숫자로 반환한다.
  15. * @returns {*}
  16. *********************************************************************************************************************/
  17. String.prototype.unNumberFormat = function() {
  18. var str = this;
  19. if(typeof str == 'number') return str;
  20. str = ("" + str).replace(/,/gi,''); // 콤마 제거
  21. str = str.replace(/(^\s*)|(\s*$)/g, ""); // trim
  22. var returnStr = new Number(str);
  23. return isNaN(returnStr) ? str : returnStr;
  24. };
  25. Number.prototype.unNumberFormat = function() {
  26. return this;
  27. };
  28. /**********************************************************************************************************************
  29. * 날짜를 원하는 포맷 형식으로 출력
  30. * @param f
  31. * @returns {*}
  32. *********************************************************************************************************************/
  33. Date.prototype.dateFormat = function(f) {
  34. if (!this.valueOf()) return " ";
  35. if (!f) return this;
  36. var weekName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"],
  37. shortWeekName = ["일", "월", "화", "수", "목", "금", "토"],
  38. d = this;
  39. return f.replace(/(yyyy|yy|MM|dd|E|hh|mm|ss|a\/p)/gi, function($1) {
  40. switch ($1) {
  41. case "yyyy": return d.getFullYear();
  42. case "yy": return (d.getFullYear() % 1000).zf(2);
  43. case "MM": return (d.getMonth() + 1).zf(2);
  44. case "dd": return d.getDate().zf(2);
  45. case "E": return weekName[d.getDay()];
  46. case "e": return shortWeekName[d.getDay()];
  47. case "HH": return d.getHours().zf(2);
  48. case "hh": return ((h = d.getHours() % 12) ? h : 12).zf(2);
  49. case "mm": return d.getMinutes().zf(2);
  50. case "ss": return d.getSeconds().zf(2);
  51. case "a/p": return d.getHours() < 12 ? "오전" : "오후";
  52. default: return $1;
  53. }
  54. });
  55. };
  56. String.prototype.string = function(len){var s = '', i = 0; while (i++ < len) { s += this; } return s;};
  57. String.prototype.zf = function(len){return "0".string(len - this.length) + this;};
  58. Number.prototype.zf = function(len){return this.toString().zf(len);};
  59. String.prototype.dateFormat = function(f) {
  60. var d = new Date(this);
  61. return ( d == 'Invalid Date') ? '' : d.dateFormat(f);
  62. }
  63. /**********************************************************************************************************************
  64. * 숫자를 한글명으로 바꿔서 보여줍니다.
  65. *********************************************************************************************************************/
  66. Number.prototype.toKorean = function() {
  67. var hanA = new Array("","일","이","삼","사","오","육","칠","팔","구","십"),
  68. danA = new Array("","십","백","천","","십","백","천","","십","백","천","","십","백","천"),
  69. num = new String(this),
  70. result = '';
  71. for(var i=0; i<num.length; i++) {
  72. var str = "",
  73. han = hanA[num.charAt(num.length-(i+1))];
  74. if(han != "") str += han+danA[i];
  75. if(i == 4) str += "만";
  76. if(i == 8) str += "억";
  77. if(i == 12) str += "조";
  78. result = str + result;
  79. }
  80. return result;
  81. }
  82. String.prototype.toKorean = function() {
  83. return (this.unNumberFormat()).toKorean();
  84. }