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>

관련자료

등록된 댓글이 없습니다.
Today's proverb
우리가 해야 할 큰 일은 먼데 있는 불명확한 것이 아니라 아주 가까이 있는 확실한 것이다. (T.칼라일)