dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: Write money amount

  1. #1
    Join Date
    May 2016
    Posts
    1

    Write money amount

    Hi experts, I have lines of code which is written in VBscript, but is not supported in all of the browsers for the windows 10 any more. I need to convert the numbers, for example, 56.35 to FIFTY SIX DOLLARS AND 35/100. Below is the code which doesn't work any more. Please advise! Thank you very much!

    <SCRIPT language=VBScript>


    CurrentAmount=document.forms(2).elements(0).value

    TempStringLen = Len(CurrentAmount)


    DollarValue = Left(CurrentAmount, TempStringLen-3)




    CentsValue = Right(CurrentAmount, 2)


    validate(DollarValue)

    document.forms(2).elements(0).value = document.forms(2).elements(0).value & " Dollars and " & CentsValue & "/100"

    document.forms(2).elements(0).value = Ucase(Trim(document.forms(2).elements(0).value))


    </SCRIPT>

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    3,657
    Visual Basic Script AKA VBScript is not JavaScript
    --> JavaScript Frameworks like JQuery, Angular, Node <-- ... and please remember to wrap any code you have in forum tags:-
    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Oct 2013
    Posts
    1,458
    This may help:
    http://stackoverflow.com/questions/1...ith-javascript
    If not I Googled javascript write currency in words to find it. Maybe something else will work better for you.
    In dog beers I've only had one.

  4. #4
    Join Date
    Sep 2007
    Posts
    390
    Code:
     
    <html>
    <head>
    <meta charset="utf-8">
    </head>
    <body>
    <input type="text" value="5432987654311556.35" id="para"><br><br>
    <input type="button" value="metne çevir"onclick="paraMetni()"><br><br>
    <div id="metin"></div>
    
    <script type="text/javascript">
    
    function paraMetni(){
    var el=document.getElementById('para');
    var p=el.value.split('.');
    var s=p[0]; var kr=p[1];
    
    var b=["","bir","iki","üç","dört","beş","altı","yedi","sekiz","dokuz"];
    var o= ["","on","yirmi","otuz","kırk","elli","altmış","yetmiş","seksen","doksan"];
    var y=["","yüz","iki yüz","üç yüz","dört yüz","beş yüz","altı yüz","yedi yüz","sekiz yüz","dokuz yüz"];
    var uclu=["","bin","milyon","milyar","tirilyon","katrilyon"];
    
    //var s = "5432987654311556";
    var L=s.length;
    var k = Math.ceil(L/3);
    // alert("k="+k);
    var t="";
    for(var i=0,n=k; i<s.length; i++){ // alert(L % 3);
    if(L % 3 == 0){t += y[s.charAt(i)]+" "; }
    if(L % 3 == 1){t += b[s.charAt(i)]+" "; t += uclu[n-1]+" "; n-- ;}
    if(L % 3 == 2){t += o[s.charAt(i)]+" "; }
    L--;
    }
    // binler basamağında 1 varken ve 4 rakam varken "bir bin"yazmasını önlemek için
    //if(s.length==4 && s.charAt(0)==1){t=t.replace("bir bin","bin");}
    
    t=t.replace(/^bir bin/,"bin");
    t += "TL ";
    
    if(kr=="00"){ t += "sıfır kuruş";}
    if(kr!="00"){ t +=  o[kr.charAt(0)]+" "+b[kr.charAt(1)]+" kuruş"; }
    
    var m=document.getElementById('metin');
    m.innerHTML =   t;
    }
    
    </script>
    </body>
    </html>
    Last edited by Ayşe; 05-26-2016 at 03:40 PM.

  5. #5
    Join Date
    Sep 2007
    Posts
    390
    Code:
      
    <html>
    <head>
    <meta charset="utf-8">
    </head>
    <body>
    <input type="text" value="5415914613312511.35" id="para"><br><br>
    <input type="button" value="metne çevir"onclick="paraMetni()"><br><br>
    <div id="metin"></div><br><br>
    <div id="metin2"></div>
    
    <script type="text/javascript">
    
    function paraMetni(){
    var el=document.getElementById('para');
    var p=el.value.split('.');
    var s=p[0]; 
    var kr=p[1];
    
    var b=["","one","two","three","four","five","six","seven","eight","nine"];
    var o= ["","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];
    var y=["","one hundred","two hundred","three hundred","four hundred","five hundred","six hundred","seven hundred","eight hundred","nine hundred"];
    
    var uclu = [ '', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quatttuor-decillion', 'quindecillion', 'sexdecillion', 'septen-decillion', 'octodecillion', 'novemdecillion', 'vigintillion', 'centillion' ];
    
    var L = s.length;
    var k = Math.ceil(L/3);
    
    var t = "";
    for(var i=0,n=k; i<s.length; i++){ // alert(L % 3);
    if(L % 3 == 0){t += y[s.charAt(i)]+" "; }
    if(L % 3 == 1){t += b[s.charAt(i)]+" "; t += uclu[n-1]+" "; n-- ;}
    if(L % 3 == 2){t += o[s.charAt(i)]+" "; }
    L--;
    }
    
    var d=["","eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "];
     alert(t);
    //"ten one" yerine "eleven" yazdırmak için
    /* döngü kullanmadan yaparsak
    t=t.replace(/ten one/g,"eleven");  
    t=t.replace(/ten two/g,"twelve"); 
    t=t.replace(/ten three/g,"thirteen");  
    t=t.replace(/ten four/g,"fourteen"); 
    t=t.replace(/ten five/g,"fifteen");  
    t=t.replace(/ten six/g,"sixteen"); 
    t=t.replace(/ten seven/g,"seventeen");  
    t=t.replace(/ten eight/g,"eighteen"); 
    t=t.replace(/ten nine/g,"nineteen");  
    */
    // döngü kullanarak yapalım bunu
    
    var z;
    var re;
    for(var i=1; i<d.length; i++){
    z="ten "+b[i];
    re =new RegExp(z,"g");
    if(t.indexOf(z)!= -1) {t=t.replace(re,d[i]); }
    }
    
     alert(t);
    t += "DOLLARS and ";
    var m2=document.getElementById('metin2');
    m2.innerHTML =   t+" "+kr+"/"+"100";
    
    if(kr=="00"){ t += "zero penny";}
    if(kr!="00"){ t +=  o[kr.charAt(0)]+" "+b[kr.charAt(1)]+" penny"; }
    
    var m=document.getElementById('metin');
    m.innerHTML =   t;
    
    }
    
    </script>
    </body>
    </html>
    Last edited by Ayşe; 05-27-2016 at 02:06 AM.

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    3,657
    One consideration is the scale and what type of convention you use, for example, a long scale UK Billion is a short scale US Trillion (10 ^ 12), although the UK has adopted the short scale in business matters, most of the world uses long scale.
    --> JavaScript Frameworks like JQuery, Angular, Node <-- ... and please remember to wrap any code you have in forum tags:-
    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  7. #7
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles