Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Best method???!!!

    Hi guy!!!
    That is a method for write this badly string:
    Code:
    
    if (arrayNumber[1] == "1" && arrayNumber[2] == "1" || arrayNumber[2] == "2" || arrayNumber[2] == "3" || arrayNumber[2] == "4" || arrayNumber[2] == "5" || arrayNumber[2] == "6" || arrayNumber[2] == "7" ||arrayNumber[2] == "8" || arrayNumber[2] == "9")
    in an other string more beautifull ???
    Last edited by triko; 01-09-2013 at 07:28 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    You didn't increment the array index past 2 in your example; also, the first position in a JavaScript array is 0, not 1.

    Code:
    if((arrayNumber[0] == "1" && arrayNumber[1] == "2") ||
       (arrayNumber[1] == "3" && arrayNumber[2] == "3") ||
    ...
       (arrayNumber[9] == "10" && arrayNumber[10] == "11")){
    Also, these are evaluating as strings, not integers. Did you want integer values?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    Rewriting *ONLY* what you showed there, not attempting to extend it as WolfShade did:
    Code:
    var s = arrayNumber[1] + arrayNumber[2];
    if ( ( /^1[1-9]$/ ).test(s) )
    {
        // pattern is 1 followed by any digit except 0
    } else {
       // pattern is not matched
    }
    Maybe if you *DESCRIBED* what you want instead of writing bad JS code we could help you more?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Yes, you're right!!
    In my problem i do translate from number ex : 125020 to letters, one hundred twenty-five thousand and twenty!
    And i use more if and put an condition if number from 1 to 9
    But can you explain me what means this symbol ? : if ( ( /^1[1-9]$/ ).test(s) )

  • #5
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Try this for number to 1000...
    Code:
    <body>
    <h2>«&nbsp;How to spell numbers ?&nbsp;»</h2>
    <p><input type="text" id="ntr" onkeyup="readNmb(this.value)"></p>
    <p id="rsp"></p>
    <script type="text/javascript">
    function $(i) {return document.getElementById(i)};
    
    function nmb(n){var c,m,r;
    	c='';r=0;s=0;
     	if (100<=n) {m=Math.floor(n/100);c+=nmb(m)+' hundred';n-=m*100}
    	if (90<=n) {c+=' ninety';n-=90;}
    	if (80<=n) {c+=' eighty';n-=80;}
    	if (70<=n) {c+=' seventy';n-=70;}
    	if (60<=n) {c+=' sixty';n-=60;}
    	if (50<=n) {c+=' fifty';n-=50;}
    	if (40<=n) {c+=' forty';n-=40}
    	if (30<=n) {c+=' thirty';n-=30;}
    	if (20<=n) {c+=' twenty';n-=20}
    	if (0==n) return c;
    	else if (c && n<10) c+='-';
    	return c+' '+'zero,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen'.split(',')[n];
    }
    function readNmb(v){
    	$('rsp').innerHTML=nmb(v).replace(/- /g,'-');
    }
    </script>
    </body>
    </html>
    Then try to cut bigger numbers...

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    Quote Originally Posted by triko View Post
    In my problem i do translate from number ex : 125020 to letters, one hundred twenty-five thousand and twenty!
    So what is the point in testing just the FIRST TWO characters, as your ugly code was trying to do?
    But can you explain me what means this symbol ? : if ( ( /^1[1-9]$/ ).test(s) )
    / ==>> beginning of a regular expression
    ^ ==>> beginning of text (that is, nothing can appear before what we are testing)
    1 ==>> the digit 1, only. Nothing else allowed.
    [1-9] ==>> any digit from 1 to 9
    $ ==>> the end of the text (nothing can appear after what we are testing)
    / ==>> the end of the regular expression

    In short, that says "Look for text that has a 1 as the first character and a 1 through 9 as the second character and is exactly 2 characters long."

    But who cares? It's entirely irrelevant to what you really need.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    Is this what you are trying to accomplish?
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Numbers to words</title>
    <style type="text/css">
    * { font-size: x-large; }
    </style>
    </head>
    <body>
    <div>
    <form>
        Enter a number: <input id="theNumber" />
        <hr />
        That number in words:<br />
           <span id="words"></span>
    </form>
    </div>
    
    <script type="text/javascript">
    var UnitNames = [" zero"," one"," two"," three"," four", 
                     " five"," six"," seven"," eight"," nine" ];
    var TeenNames = [" ten"," eleven"," twelve"," thirteen"," fourteen", 
                     " fifteen"," sixteen"," seventeen"," eighteen"," nineteen" ];
    var DecadeNames = [" zero"," ten"," twenty"," thirty"," forty", 
                     " fifty"," sixty"," seventy"," eighty"," ninety" ];
    
    document.getElementById("theNumber").onchange =
        function( ) 
        {
            var text = document.getElementById("words");
            text.innerHTML = NumberAsWord( parseInt(this.value) );
        };
    
    function NumberAsWord( num )
    {
        
        var millions, thousands, hundreds, decades, result;
    
        if ( isNaN(num) )
        {
            return "<i>That is NOT a valid number!</i>";
        }
        if ( num == 0 )
        {
            return "zero";
        }
        result = "";
        if ( num < 0 ) 
        {
            num = - num;
            result = "<i>NEGATIVE</i> ";
        }
        millions = Math.floor( num / 1000000 );
        num %= 1000000;
        if ( millions > 0 )
        {
            if ( millions > 999 )
            {
                return "BILLIONS and BILLIONS";
            }
            result += NumberAsWord( millions ) + " million"
            if ( num == 0 ) return result;
        }
        
        thousands = Math.floor( num / 1000 );
        num %= 1000;
        if ( thousands > 0 )
        {
            result += NumberAsWord( thousands ) + " thousand"
            if ( num == 0 ) return result;
        }
        hundreds = Math.floor( num / 100 );
        num %= 100;
        if ( hundreds > 0 )
        {
            result += UnitNames[ hundreds ] + " hundred"
        }
        decades = Math.floor( num / 10 );
        num %= 10;
        if ( decades == 1 )
        {
            result += TeenNames[ num ];
        } else {
            if ( decades > 1 )
            {
                result += DecadeNames[ decades ];
            }
            if ( num > 0 )
            {
                result += UnitNames[ num ];
            }
        }
        return result;
    }
    </script>
    </body>
    </html>
    Last edited by Old Pedant; 01-11-2013 at 09:06 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Is this what you are trying to accomplish?
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Numbers to words</title>
    <style type="text/css">
    * { font-size: x-large; }
    </style>
    </head>
    <body>
    <div>
    <form>
        Enter a number: <input id="theNumber" />
        <hr />
        That number in words:<br />
           <span id="words"></span>
    </form>
    </div>
    
    <script type="text/javascript">
    var UnitNames = [" zero"," one"," two"," three"," four", 
                     " five"," six"," seven"," eight"," nine" ];
    var TeenNames = [" ten"," eleven"," twelve"," thirteen"," fourteen", 
                     " fifteen"," sixteen"," seventeen"," eighteen"," nineteen" ];
    var DecadeNames = [" zero"," ten"," twenty"," thirty"," forty", 
                     " fifty"," sixty"," seventy"," eighty"," ninety" ];
    
    document.getElementById("theNumber").onchange =
        function( ) 
        {
            var text = document.getElementById("words");
            text.innerHTML = NumberAsWord( parseInt(this.value) );
        };
    
    function NumberAsWord( num )
    {
        
        var millions, thousands, hundreds, decades, result;
    
        if ( isNaN(num) )
        {
            return "<i>That is NOT a valid number!</i>";
        }
        if ( num == 0 )
        {
            return "zero";
        }
        result = "";
        if ( num < 0 ) 
        {
            num = - num;
            result = "<i>NEGATIVE</i> ";
        }
        millions = Math.floor( num / 1000000 );
        num %= 1000000;
        if ( millions > 0 )
        {
            if ( millions > 999 )
            {
                return "BILLIONS and BILLIONS";
            }
            result += NumberAsWord( millions ) + " million"
            if ( num == 0 ) return result;
        }
        
        thousands = Math.floor( num / 1000 );
        num %= 1000;
        if ( thousands > 0 )
        {
            result += NumberAsWord( thousands ) + " thousand"
            if ( num == 0 ) return result;
        }
        hundreds = Math.floor( num / 100 );
        num %= 100;
        if ( hundreds > 0 )
        {
            result += UnitNames[ hundreds ] + " hundred"
        }
        decades = Math.floor( num / 10 );
        num %= 10;
        if ( decades == 1 )
        {
            result += TeenNames[ num ];
        } else {
            if ( decades > 1 )
            {
                result += DecadeNames[ decades ];
            }
            if ( num > 0 )
            {
                result += UnitNames[ num ];
            }
        }
        return result;
    }
    </script>
    </body>
    </html>
    :O :O :O :O :O :O :O
    Don ' t have word!!! Very unbelievable program.... You are a pro!!! my program is very bad....
    and don t work well!!!
    Code:
    <!DOCTYPE>
    <html>
        <head><title>Converter</title>
            <script>
                function convert ()
                {
                    var final = "";
                    var foo = 0;
                    var text = document.getElementById("number").value;
                    var len = text.length;
                    var arrayUnità = ["", "uno" , "due" , "tre", "quattro", "cinque", "sei", "sette", "otto", "nove"];
                    var arrayPrimi = ["", "undici", "dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove"];
                    var arrayDecine = ["", "dieci", "venti", "trenta", "quaranta", "cinquanta", "sessanta", "settanta", "ottanta", "novanta"];
                    var cento = "cento";
                    var mille = "mille";
                    var mila = "mila";
                    var arrayNumber = [];
                    for (i = 0; i < len; i ++)
                    {
                        arrayNumber[foo] = text[foo];
                        foo++;
                    }
                    for (i = 0; i < len; i++)
                    {
                        if (len == 4)
                        {
                            for (a = 0; a < len; a++)
                            {
                                if (arrayNumber[0] == "1" && arrayNumber[1] == "1" && arrayNumber[2] == "1")
                                {
                                    var f = arrayNumber[a];
                                    final = mille + cento;
                                    a = 3;
                                    var f = arrayNumber[a];
                                    final += arrayPrimi[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[0] == "1" && arrayNumber[1] != "1" && arrayNumber[2] != "1")
                                {
                                    final = mille;
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[0] == "1" && arrayNumber[1] != "1" && arrayNumber [2] == "1" && (arrayNumber[3] == "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9"))
                                {
                                    final = mille;
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f] + cento;
                                    a = 3;
                                    var f = arrayNumber[a];
                                    final += arrayPrimi[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[0] == "1" && arrayNumber[1] == "1" && arrayNumber[2] != "1")
                                {
                                    final = mille + cento;
                                    a = 2;
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[1] == "1" && arrayNumber[2] == "1")
                                {
                                    var f = arrayNumber[a];
                                    final = arrayUnità[f] + mila + cento;
                                    a = 3;
                                    var f = arrayNumber[a];
                                    final += arrayPrimi[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[1] == "1" && arrayNumber[2] != "1")
                                {
                                    var f = arrayNumber[a];
                                    final = arrayUnità[f] + mila + cento;
                                    a = 2;
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[0] != "1" && arrayNumber[1] == "0" && arrayNumber[2] == "0" && (arrayNumber[3] == "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9"))
                                {
                                    var f = arrayNumber[a];
                                    final = arrayUnità[f] + mila;
                                    a = 3;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[0] != "1" && arrayNumber[1] == "0" && arrayNumber[2] != "1")
                                {
                                    var f = arrayNumber[a];
                                    final = arrayUnità[f] + mila;
                                    a = 2;
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[0] != "1" && arrayNumber[1] == "0" && arrayNumber[2] == "1" && (arrayNumber[3] == "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9"))
                                {
                                    var f = arrayNumber[a];
                                    final = arrayUnità[f] + mila;
                                    a = 2;
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayPrimi[f];
                                    alert (final);
                                    return;
                                }
                                else
                                {
                                    var f = arrayNumber[a];
                                    final = arrayUnità[f] + mila;
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f] + cento;
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    alert (final);
                                }
                            }
                        }
                        if (len == 3)
                        {
                            for (a = 0; a < len; a++)
                            {
                                if (arrayNumber[1] == "1" && (arrayNumber[2] == "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9"))
                                {
                                    final = cento;
                                    a = 2;  
                                    var f = arrayNumber[a];
                                    final += arrayPrimi[f];
                                    alert (final);
                                    return;
                                }
                                if (arrayNumber[0] == "1")
                                {
                                     // ora è 9, ad ogni ciclo passa al numero dopo!!
                                    final = cento;
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    aler(final);
                                    return;
                                }
                                else
                                {
                                    var f = arrayNumber[a] // ora è 9, ad ogni ciclo passa al numero dopo!!
                                    final = arrayUnità[f] + cento;
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a];
                                    final += arrayUnità[f];
                                    alert(final);
                                    return;
                                }
                            }
                        }
                        if (len == 2)
                        {
                            for (a = 0; a < len; a++)
                            {
                                if (arrayNumber[0] == 1 && (arrayNumber[2] == "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9"))
                                {
                                    a++;
                                    var f = arrayNumber[a];
                                    final = arrayPrimi[f];
                                }
                                else
                                {
                                    var f = arrayNumber[a];
                                    final += arrayDecine[f];
                                    a++;
                                    var f = arrayNumber[a]
                                    final += arrayUnità[f];
                                }
                                alert (final);
                            }
                        }
                        if (len == 1)
                        {
                            if (arrayNumber[0] == "0")
                            {
                                alert ("zero");
                            }
                            else
                            {
                                a = 0;
                                var f = arrayNumber[a];
                                final = arrayUnità[f];
                                alert (final);
                            }
                        }
                        len = 0;
                    }
                }
            </script>
        </head>
        <body>
            <p>Insert number of max 4 character</p>
            <input type = "text" id = "number" /> <br /><br />
            <button type="button" onclick="convert ()"> CONVERT TO STRING </button>
        </body>
    </html>

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    The rules for English numbers are surely different than the rules for Italian numbers, but I would think you can find a way to adapt my code.

    I do see that Italian treats 10 through 19 differently than 20 through 99, same as English, so it might not be too hard to adapt.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    A variant with hyphens (in line on this page) :
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="fr">
    <head>
    <title>Number's literal shapes</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <style type="text/css">
    body,input {font-family:georgia;font-size:medium;color:#000066;}
    body {margin:0px;padding:20px;}
    #pge {display:block;width:600px;margin:0 auto;padding:7px;}
    td {padding:7px;font-size:small;text-align:top}
    input{text-align:center;font-family:georgia;font-size:small;}
    #rsp {font-size:medium;}
    </style>
    </head>
    <body>
    <div id="pge"><fieldset><legend>Number's literal shapes</legend>
    <table>
    	<tr><td><input type="text" id="ntr" maxlength="15" onkeyup="readNmb(this.value)">
    		<br><input type="radio" id="shc" name="rdb" checked="checked" onclick="readNmb($('ntr').value)">&nbsp;Short scale</br>
    		<input type="radio" name="rdb" onclick="readNmb($('ntr').value)">&nbsp;Long scale</td>
    		<td id="rsp"></td></tr></table>
    </fieldset>
    </div>
    <script type="text/javascript">
    function $(i) {return document.getElementById(i)};
    
    function triplets(n){var c='',m;
     	if (100<=n) {m=Math.floor(n/100);c+=triplets(m)+' hundred';n-=m*100}
    	n.toString().replace(/^[2-9](?=\d)/,function(a){
    		c+=' '+('twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety'.split(',')[a-2]);n-=(+a)*10});
    	if (n==0) return c;else if (c && n<10) c+='-';
    	return c+' '+'one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen'.split(',')[n-1];
    }
    function anyNumber(n){var lng,isS;
    	wds=($('shc').checked?' ,thousand,million,billion,trillion':' ,thousand,million,milliard,billion').split(',');
    	n.replace(/(\d{1,3})(?=((\d\d\d)*)$)/g,function(a,b,c){ 
    		 if (c && c!='undefined') lng=c.toString().length/3;else lng=0;
    		 if (isS=triplets(a.replace(/^0+/,''))) $('rsp').innerHTML+='<br>'+isS.replace(/- /g,'-')+' '+wds[lng];
    	});
    }
    function readNmb(w){
    	if (!w) $('rsp').innerHTML=''; 
    	else {$('rsp').innerHTML='<b>'+w.replace(/(\d)(?=(\d\d\d)+$)/g,'$1,')+'</b> is written :';
    		w=w.replace(/^0+/,'');
    		if (!w) $('rsp').innerHTML+='<br>zero'; 
    		else anyNumber(w);}
    }
    $('ntr').focus();
    </script>
    </body>
    </html>
    EDIT : An essay with Italian...
    Code:
    <body>
    <div id="pge"><fieldset><legend>Italian numbers</legend>
    <table>
    	<tr><td><input type="text" id="ntr" maxlength="15" onkeyup="readNmb(this.value)">
    		<td id="rsp"></td>
    	</tr></table>
    </fieldset>
    </div>
    <script type="text/javascript">
    function $(i) {return document.getElementById(i)};
    
    function triplets(n){var c='',m;
     	if (100<=n) {m=Math.floor(n/100);c+=triplets(m)+'cento';n-=m*100}
    	n.toString().replace(/^[2-9](?=\d)/,function(a){
    		c+='venti,trenta,quaranta,cinquanta,sessanta,settenta,ottanta,novanta'.split(',')[a-2];n-=(+a)*10});
    	if (n==0) return c;
    	return c+'uno,due,tre,quattro,cinque,sei,sette,otto,nove,dieci,undici,dodici,tredici,quattrodici,quindici,sedici,diciasette,diciotto,dicianove'.split(',')[n-1];
    }
    function anyNumber(n){var lng,trp,isS,chn='',m;
    	n.replace(/(\d{1,3})(?=((\d\d\d)*)$)/g,function(a,b,c){ 
    	    if (c && c!='undefined') lng=c.toString().length/3;else lng=0;
    	    isS=triplets(m=a.replace(/^0+/,''));
    	    trp=' ,mille,milione,miliardo,bilione'.split(',')[lng];
    		 if (1<m) trp=trp.replace(/mille/,'milla');
    		 if (isS) chn+=' '+isS+trp;
    	});
    	$('rsp').innerHTML+=chn.replace(/\wtre$/g,'$1tré').replace(/(a|i|u|o)(a|o)/g,'$2');
    }
    function readNmb(w){
    	if (!w) $('rsp').innerHTML=''; 
    	else {$('rsp').innerHTML='<b>'+w.replace(/(\d)(?=(\d\d\d)+$)/g,'$1.')+'</b> si scritti :<br>';
    		w=w.replace(/^0+/,'');
    		if (!w) $('rsp').innerHTML+='zero'; 
    		else anyNumber(w);}
    }
    $('ntr').focus();
    </script>
    </body>
    Last edited by 007julien; 01-14-2013 at 10:49 AM. Reason: complements

  • #11
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    .. O god!! Julien, this code is suicide for me!!! Don't understand nothing.. it's for high programmers quality!! But thanks

  • #12
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    The rules for English numbers are surely different than the rules for Italian numbers, but I would think you can find a way to adapt my code.

    I do see that Italian treats 10 through 19 differently than 20 through 99, same as English, so it might not be too hard to adapt.
    OK Pedant, I will try to adapt! Thanks

  • #13
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    The proposed code treats strings rather than numbers. The function anyNumber cuts simply and logically the numbers in three digits slices with a replace method (the regular expression captures each one to three digit slice, before a multiple of three digits) not to replace this slices with return values, but only to call the function for triplets and to define the future response chn...

    EDIT : Change the chn.replace(/tre$/g,'tré') with a chn.replace(/(\w)tre\b/g,'$1tré') to replace tre by tré only at the end of a word (after a letter).
    Last edited by 007julien; 01-14-2013 at 09:04 AM. Reason: errors

  • #14
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Just an essay to count in Europa... It still lacks many languages (and there are probably still errors) !

  • #15
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    Quote Originally Posted by 007julien View Post
    Just an essay to count in Europa... It still lacks many languages (and there are probably still errors) !
    Very nice! Now let's see it in Japanese. <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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