Transformateur de chiffres en lettres
Codes à insérer entre les balises <HEAD> et </HEAD> de votre document HTML
<script language="JavaScript"> // Script trouvé sur www.utilsfr.fr.fm // Retrouvez des centaines de scripts et bien plus... <!-- Begin var n = ""; function validate(input) { if (input.length == 0) { alert ('Ce n\'est pas un nombre !'); document.myform.textver.value = ""; return true; }else convert(input); }function d1(x) { switch(x) { case '0': n= ""; break; case '1': n= " Un "; break; case '2': n= " Deux "; break; case '3': n= " Trois "; break; case '4': n= " Quatre "; break; case '5': n= " Cinq "; break; case '6': n= " Six "; break; case '7': n= " Sept "; break; case '8': n= " Huit "; break; case '9': n= " Neuf "; break; default: n = "Ce n\'est pas un nombre"; } return n; } function d2(x) { switch(x) {case '0': n= ""; break; case '1': n= ""; break; case '2': n= " Vingt "; break; case '3': n= " Trente "; break; case '4': n= " Quarante "; break; case '5': n= " Cinquante "; break; case '6': n= " Soixante "; break; case '7': n= " Soixante-dix "; break; case '8': n= " Quatre-vingts "; break; case '9': n= " Quatre-vingt-dix "; break; default: n = "Ce n\'est pas un nombre"; } return n; } function d3(x) { switch(x) { case '0': n= " Dix "; break; case '1': n= " Onze "; break; case '2': n= " Douze "; break; case '3': n= " Treize "; break; case '4': n= " Quatorze "; break; case '5': n= " Quinze "; break; case '6': n= " Seize "; break; case '7': n= " Dix sept "; break; case '8': n= " Dix huit"; break; case '9': n= " Dix neuf "; break; default: n= "Ce n\'est pas un nombre !"; } return n; } function convert(input) { var inputlength = input.length; var x = 0; var teen1 = ""; var teen2 = ""; var teen3 = ""; var numName = ""; var invalidNum = ""; var a1 = ""; var a2 = ""; var a3 = ""; var a4 = ""; var a5 = ""; digit = new Array(inputlength); for (i = 0; i < inputlength; i++) { digit[inputlength - i] = input.charAt(i)}; store = new Array(9); for (i = 0; i < inputlength; i++) { x= inputlength - i;switch (x) { case x=9: d1(digit[x]); store[x] = n; break; case x=8: if (digit[x] == "1") {teen3 = "yes"} else {teen3 = ""}; d2(digit[x]); store[x] = n; break; case x=7: if (teen3 == "yes") {teen3 = ""; d3(digit[x])} else {d1(digit[x])}; store[x] = n; break; case x=6: d1(digit[x]); store[x] = n; break; //lwf case x=5: if (digit[x] == "1") {teen2 = "yes"} else {teen2 = ""}; d2(digit[x]); store[x] = n; break;case x=4: if (teen2 == "yes") {teen2 = ""; d3(digit[x])} else {d1(digit[x])}; store[x] = n; break; case x=3: d1(digit[x]); store[x] = n; break; case x=2: if (digit[x] == "1") {teen1 = "yes"} else {teen1 = ""}; d2(digit[x]); store[x] = n; break; case x=1: if (teen1 == "yes") {teen1 = "";d3(digit[x])} else {d1(digit[x])}; store[x] = n; break; } if (store[x] == "Ce n\'est pas un nombre !"){invalidNum = "yes"}; switch (inputlength){ case 1: store[2] = ""; case 2: store[3] = ""; case 3: store[4] = ""; case 4: store[5] = ""; case 5: store[6] = ""; case 6: store[7] = ""; case 7: store[8] = ""; case 8: store[9] = ""; } if (store[9] != "") { a1 =" Milliers, "} else {a1 = ""}; if ((store[9] != "")||(store[8] != "")||(store[7] != "")) { a2 =" Millions, "} else {a2 = ""}; if (store[6] != "") { a3 =" Cent "} else {a3 = ""}; if ((store[6] != "")||(store[5] != "")||(store[4] != "")) { a4 =" Mille, "} else {a4 = ""}; if (store[3] != "") { a5 =" Cent "} else {a5 = ""}; } if (invalidNum == "yes"){numName = "Invalid Input"} else { numName = store[9] + a1 + store[8] + store[7] + a2 + store[6] + a3 + store[5] + store[4] + a4 + store[3] + a5 + store[2] + store[1]; } store[1] = ""; store[2] = ""; store[3] = ""; store[4] = ""; store[5] = ""; store[6] = ""; store[7] = ""; store[8] = ""; store[9] = ""; if (numName == ""){numName = "Zéro"}; document.myform.textver.value = numName;return true; } // End --> </script> Cliquez ici pour tout sélectionner
Codes à insérer entre les balises <BODY> et </BODY> de votre document HTML
<form name="myform"> <table border="0"> <tr> <td>Nombre :</td> <td><input type="text" size="9" maxlength="9" name="numver"> <input type="button" value="Tranformer !" onclick="return validate(document.myform.numver.value)"></td> </tr> <tr> <td>Texte :</td> <td><input type="text" size="50" maxlength="50" name="textver"></td> </tr> </table> </form> Cliquez ici pour tout sélectionner