Html & Script

[JavaScript] 숫자 -> 한글변환

컨텐츠 정보

본문

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function num2han(string)
{
              hn = new Array("영","일","이","삼","사","오","육","칠","팔","구");
              hj = new Array("","만","억","조","경","해","시","양","구","간","정","재","극","항하사","아승지","나유타","불가사의","무량대수");
              ul = new Array("영천","영백","영십","영");
              tm = new Array();
                      result = "";

              if (string.charAt(0)=="-"){ result = "마이너스 ";              string = string.substr(1,string.length-1); }
              loop_size = Math.ceil(string.length/4);
                      string2 = "";
              for (count=string.length; count >= 0; count--)
                  string2 += string.substring(count,count-1);
                      string = string2;
              for (A=0;A<loop_size;A++)
              {
                            sum = hj[A] + " ";
                                                tm[A] = string.substr(A*4,4);

                            tm2 = "";
                                                for (count=tm[A].length; count >= 0; count--)
                                tm2 += tm[A].substring(count,count-1);
                                    tm[A] = tm2;
                            part_jari = tm[A].length;
                                                for (D=0;D<10;D++){
                                for (B=0;B<10;B++) tm[A] = tm[A].replace(B,hn[B]);
                                                }

                            if (part_jari == 4) tm[A] = tm[A].charAt(0)+"천"+tm[A].charAt(1)+"백"+tm[A].charAt(2)+"십"+tm[A].charAt(3);
                            else if (part_jari == 3) tm[A] = tm[A].charAt(0)+"백"+tm[A].charAt(1)+"십"+tm[A].charAt(2);
                            else if (part_jari == 2) tm[A] = tm[A].charAt(0)+"십"+tm[A].charAt(1);             
                            else tm[A] = tm[A].charAt(0);
                            for (C=0;C<4;C++)
                            {
                                                              if (tm[A].match(ul[C])){ part_jari--; tm[A] = tm[A].replace(ul[C],""); }
                            }
                            if (part_jari != 0) tm[A] += sum;
              }
              for (loop_size;loop_size>-1;loop_size--) result += tm[loop_size];
                      result = result.replace("undefined","")
              document.form.han.value = result;
}
//-->
</SCRIPT>
</head>

<body>
<form method=post name=form>
<input type="text" name="num" size="10" onKeyUp="num2han(this.form.num.value);">
<input type="text" name="han" size="100" disabled>
</form>
</body>
</html>

관련자료

댓글 0
등록된 댓글이 없습니다.
Today's proverb
해가 들면 어떻고, 바람이 불면 어떻고, 눈이 오면 어떠랴. 해가 들어주어도 고맙고, 바람이 불어주어도 고맙고, 눈이 와주어도 고마울 뿐. 그렇다, 고맙지 않은 것이 없다. 밤은 밤이어서 고맙고, 새벽은 새벽이어서 고맙고, 낮은 낮이어서 고맙다. 아, 고마운 삼라만상이여! (정채봉)