Solved

Converting Amount in numbers to Amount in words

Posted on 2006-11-19
2
365 Views
Last Modified: 2008-02-01
hai experts,
At present , I m developing a pdf file which uses xml and javascript..
i need to convert the amount entered in numbers to words.
could anyone help me out using javascript.

Thanks in Advance
0
Comment
Question by:mivbinfotech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 500 total points
ID: 17974687
<SCRIPT>

var nums = ['nought', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'forteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'ninteen'];
var tens = ['one', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninty'];
var pows = ['one', 'ten', 'hundred', 'thousand', 'million'];


alert(numToStr(999999999999));



function numToStrB(num, l){

     var str = new String()
     var n=eval(num);

     num = new String(num);
     var digits = num.length;


     if(digits==3){
          if(eval(num.substring(0,1))>0){
               str += nums[num.substring(0,1)] + ' ' +  pows[2] + ' ';
               l=true;
               }
               digits--;
               num = num.substr(1,3);
     }

     if(digits<=2){
          if(l ==true && eval(num)>0) str+= 'and ';
          if(eval(num)<20 && eval(num)>0){
               num=eval(num);
               str +=nums[num] + ' ';
               digits--;
          } else {
               if(eval(num.substring(0,1))>0)
                    str += tens[num.substring(0,1)] + ' ';
               

               if(eval(num.substring(1,2))>0)
                    str += nums[num.substring(1,2)] + ' ';
               
          }
     }
     
     return str;

}


function numToStr(num){

     var str = new String()
     var n=eval(num);

     num = new String(num);
     var digits = num.length;
     
     
     if(digits>=6){
          if(eval(num)>0)
               str += numToStrC(num.substr(0,digits-6), (str.length>0)) + pows[4] + ' ';      
               num = num.substr(digits-6,6);
     }

     str+=numToStrC(num, (str.length>0));
     return str;

}

function numToStrC(num,l){

     var str = new String()
     var n=eval(num);

     num = new String(num);
     var digits = num.length;

     if(digits>=4){
          if(eval(num)>0)
               str += numToStrA(num.substr(0,digits-3),l ||(str.length>0));
          num = num.substr(digits-3,3);
     }
     if(eval(num)>0)
          str += numToStrB(num, l||(str.length>0));


     return str;    
}

function numToStrA(num,l){

     var str = new String()
     var n=eval(num);

     num = new String(num);
     var digits = num.length;
     if(eval(num)>0)
          str += numToStrB(num,(str.length>0),l||(str.length>0)) + pows[3] +' ' ;
     return str;
}


</SCRIPT>
0
 
LVL 2

Author Comment

by:mivbinfotech
ID: 17974782
thks a lot
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question