- Ce sujet est vide.
-
Sujet
-
voilà j’ai récupérai un script pour transformer un nombre en lettres:
Code:aTens = [ “vingt”, “trente”, “quarante”, “cinquante”, “soixante”, “soixante-dix”, “quatre-vingt”, “quatre-vingt-dix”];
aOnes = [ “zéro”, “un”, “deux”, “trois”, “quatre”, “cinq”, “six”, “sept”, “huit”, “neuf”, “dix”, “onze”, “douze”, “treize”, “quatorze”, “quinze”, “seize”, “dix-sept”, “dix-huit”, “dix-neuf” ];
function ConvertToHundreds(num)
{
var cNum, nNum;
var cWords = “”;num %= 1000;
if (num > 99) {
/* Hundreds. */
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aOnes[nNum] + ” cent(s)”;
num %= 100;
if (num > 0)
cWords += ” “
}
if (num > 19) {
/* Tens. */
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aTens[nNum – 2];
num %= 10;
if (num > 0)
cWords += “-“;
}if (num > 0) {
/* Ones and teens. */
nNum = Math.floor(num);
cWords += aOnes[nNum];
}return cWords;
}function ConvertToWords(num)
{
var aUnits = [ “mille(s)”, “million(s)”, “milliard(s)”, “trilliard(s)”, “quadrillion(s)” ];
var cWords = (num >= 1 && num < 2) ? "euro et " : "euros et ";
var nLeft = Math.floor(num);
for (var i = 0; nLeft > 0; i++) {
if (nLeft % 1000 > 0) {
if (i != 0)
cWords = ConvertToHundreds(nLeft) + ” ” + aUnits + ” ” + cWords;
else
cWords = ConvertToHundreds(nLeft) + ” ” + cWords;
}
nLeft = Math.floor(nLeft / 1000);
}
num = Math.round(num * 100) % 100;
if (num > 1)
cWords += ConvertToHundreds(num) + ” centimes”;
else if (num == 1)
cWords += ConvertToHundreds(num) + ” centime”;
else
cWords += “zéro centime”;return cWords;
}
ma question est: comment supprimer les centimes et donc arrondir le nombre sans décimales ?
merci d’avance
@+
- Vous devez être connecté pour répondre à ce sujet.