ํ•œ๊ธ€ -> ์ˆซ์ž

function korToNum(value) {
  var numKor = '์˜์ผ์ด์‚ผ์‚ฌ์˜ค์œก์น ํŒ”๊ตฌ';
  var numUnit1 = { '์‹ญ': 10, '๋ฐฑ': 100, '์ฒœ': 1000 };
  var numUnit2 = { '๋งŒ': 10000, '์–ต': 100000000, '์กฐ': 1000000000000 };

  var num = 0;
  var ret = 0;
  var total = 0;

  for (var i = 0; i < value.length; i++) {
    var n = value.charAt(i);

    if (numKor.indexOf(n) != -1) {
      num = numKor.indexOf(n);
    }
    else if (n in numUnit1) {
      if (num == 0) num = 1;
      ret += num + numUnit1[n];
    }
    else if (n in numUnit2) {
      if (ret == 0 && num == 0) return "";
      total += (ret + num) * numUnit2[n];
      ret = 0;
      num = 0;
    }
    else return "";
  }
  total += ret + num;
  return total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

 

์ˆซ์ž -> ํ•œ๊ธ€

function numToKor(value) {

  value = value.replace(/[^0-9]/g, '');

  var numKor = '์˜์ผ์ด์‚ผ์‚ฌ์˜ค์œก์น ํŒ”๊ตฌ';
  var numUnit1 = ' ์‹ญ๋ฐฑ์ฒœ';
  var numUnit2 = ' ๋งŒ์–ต์กฐ';

  var num = "";
  var ret = "";
  var total = "";

  var j = 0;
  while (Value > 0) {
    num = Number(value) % 10000;
    value = parseInt(Number(value) / 10000);

    for (var i = 0; i < 4; i++) {
      if (num % 10 != 0)
        ret = numKor.charAt(num % 10) + numUnit1.charAt(i) + ret;
      num = parseInt(num / 10);
    }
    if (ret != "")
      total = ret + numUnit2.charAt(j) + total;
    ret = "";
    j++;
  }
  return total.replace(/ /g, "");
}
728x90

BELATED ARTICLES

more