Forum Home Forum Home > Information Technology > The programming language > Java, Java script
  New Posts New Posts RSS Feed: Chuyển đổi từ số sang chữ javascript
  FAQ FAQ  Forum Search   Register Register  Login Login

Chuyển đổi từ số sang chữ javascript

 Post Reply Post Reply
Author
admingroup View Drop Down
Admin
Admin

ad

Joined: 14 October 2005
Online Status: Offline
Posts: 448
  Quote admingroup Quote  Post ReplyReply Direct Link To This Post Topic: Chuyển đổi từ số sang chữ javascript
    Posted: 22 December 2009 at 13:34

 
//Phanmemhanoi.com  
 
 
function Num2Text(s)
  {
   var l=0;
   var i=0;
   var j=0;
   var dk = false;
   var c ="";
   
   l = s.length;
 
     var A=new Array();

    
if (l > 32)// so qua lon
    return "Số qu lớn";

   for (i = 0; i < l; i++)
   {
    A =s.substr(i,1);     
   

   }   

   for (i = 0; i < l; i++)
   {
    if (A[0] == 0)    
    
       //throw new FormatException();
     throw new FormatException();
    
    if (( (l - i) % 3 == 0) && (A == 0) && ((A[i + 1] != 0 || A[i + 2] != 0)))
     c += " kh&#244;ng";
     

    if (A == 2) c += " hai";
    if (A == 3) c += " ba";
    if (A == 4)
    {
     if ((i - 1 > 0) && A[i-1] == 0)
      c += " t&#432;";
     else
      c += " b&#7889;n";
    }
    if (A == 6) c += " s&#225;u";
    if (A == 7) c += " b&#7843;y";
    if (A == 8) c += " t&#225;m";
    if (A == 9) c += " ch&#237;n";

    if (A == 5)
    {
     if (i > 0 && ((l - i)%3 == 1) && (A[i-1] != 0))
      c += " l&#259;m";
     else
      c += " n&#259;m";
    }

    if(i == 1 && (A == 1) && ((l - i) % 3 == 1) && (A[i - 1] > 1))
     c += " m&#7889;t";

    else if (((l - i) % 3 != 2) && (A == 1))
     c += " m&#7897;t";

    if (((l - i) % 3 == 2) && (A != 0) && (A != 1))
     c += " m&#432;&#417;i";
    else if (((l - i) % 3 == 2) && A != 0)
     c += " m&#432;&#7901;i";    

    if (((l - i) % 3 == 2) && (A == 0) && (A[i + 1] != 0))
     c += " linh";

    if (((l - i) % 3 == 0) && (A[i + 1] != 0 || A[i + 2] != 0))
     c += " tr&#259;m";
    else if (((l - i) % 3 == 0) && (A != 0))
     c += " tr&#259;m";

    if ((l - i) == 4)  c += " ngh&#236;n";
    if ((l - i) == 7)  c += " tri&#7879;u";
    if ((l - i) == 10) c += " t&#7927;";
    if ((l - i) == 13) c += " nghn t&#7927;";
    if ((l - i) == 16) c += " tri&#7879;u t&#7927;";
    if ((l - i) == 19) c += " t&#7927; t&#7927;";
    if ((l - i) == 22) c += " tri&#7879;u t&#7927; t&#7927;";
    if ((l - i) == 25) c += " tri&#7879;u t&#7927; t&#7927;";
    if ((l - i) == 28) c += " t&#7927; t&#7927; t&#7927;";

    
    if (((l - i) % 3 == 0) && (A == 0) && (A[i + 1] == 0) && (A[i + 2] == 0))
     i = i + 2;

    if ((l - i) % 3 == 1) dk = true;
    for (j = i; j < l; j++)
    {
     if(A[j] != 0)
      dk = false;
    }    

    if (dk)
     break;
    
   }
   return c + '';      
  }


 

 



Edited by admingroup - 29 December 2009 at 15:39
software and music
           
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down



This page was generated in 0.090 seconds.
Web link
here | )
[Free Express Edition]
Copyright ©2001-2009 Web Wiz

Support: raovatphanmem Support: Info hanoi software
Online(s): 323.
Visitors Counter:2363337, AVERAGE/day(570) is: 4146
Begin count is day 02/16/2009

You are browsing this site with: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)

Your IP address is: 38.107.191.99

The DNS lookup of the IP address is: 38.107.191.99

The method used to call the page: GET

The server's domain name: www.phanmemhanoi.com