oobox
Messages postés5Date d'inscriptionvendredi 19 mars 2004StatutMembreDernière intervention15 septembre 2008
-
12 sept. 2008 à 21:12
oobox
Messages postés5Date d'inscriptionvendredi 19 mars 2004StatutMembreDernière intervention15 septembre 2008
-
15 sept. 2008 à 16:45
Bonjour,
Je commence en flash et je recherche la methode pour tout simplement formater à l'affichage un nombre en ajoutant des espace du style 1 000 000
function ajouter() {
total = Math.round (a + b)
}
a = 500000;
b = 550000;
et j'affiche le total dans un var
mais le resultat affiche 1500000 et non pas 1 500 000
merci pour vos conseils
Skev
Messages postés255Date d'inscriptionmardi 27 juin 2006StatutMembreDernière intervention 9 janvier 20103 15 sept. 2008 à 16:16
C'est normal, dans ma fonction j'utilise deux variable ( "total_format" et "total_string"), or toi tu ne les declares, ni utiliser nul part.
A la limite on pourrait le simplifier comme ceci :
//Code
function ajouter() {
total = Formate(Math.round(a+b));
}
a = 500000;
b = 550000;
//
function Formate(total_non_format) {
//
total_string = new String(total_non_format);
//
if (total_string.length>9) {
total_format = total_string.slice(0, -9)+" "+total_string.slice(total_string.length-9, -6)+" "+total_string.slice(total_string.length-6, -3)+" "+total_string.slice(total_string.length-3);
} else if (total_string.length>6) {
total_format = total_string.slice(0, -6)+" "+total_string.slice(total_string.length-6, -3)+" "+total_string.slice(total_string.length-3);
} else if (total_string.length>3) {
total_format = total_string.slice(0, -3)+" "+total_string.slice(total_string.length-3);
} else if (total_string.length<=3) {
total_format = total_string;
}
return (total_format);
}
//
ajouter();
//
trace(total);