begin process at 2012 02 10 09:55:09
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Flash / Flash MX

 > 

Divers

 > 

Débutant(e)

 > 

Formater l'affichage d'un nombre


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Formater l'affichage d'un nombre

vendredi 12 septembre 2008 à 21:12:16 | Formater l'affichage d'un nombre

oobox


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
lundi 15 septembre 2008 à 14:55:11 | Re : Formater l'affichage d'un nombre

Skev

Bonjour,
J'avais creer une fonction simmilaire pour un jeux , l'argent etait trop peu lisible,
Je te met mon code melangé a ta fonction :

///////////////////Code
function ajouter() {
    total = Math.round(a+b);
}
a = 500000;
b = 550000;
//
ajouter();
//
total_string = new String(total);
//
function Formate() {
    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;
    }
}
Formate();
//
trace(total_format);
///////////////////

Rq : il peut être optimiser je pense, il fait carrément brouillon !
lundi 15 septembre 2008 à 15:31:20 | Re : Formater l'affichage d'un nombre

oobox

Merci pour ta réponse
je vais essayer d'intégrer ton code.

form:
1 texte de saisie Var: montant
1 Texte dynamique Var : total

Actions :

function ajouter() {
  total = Formate(montant * 10);
}
// EST CE QUE CETTE FONCTION PEUT FONCTIONNER AINSI ?
// Formate(montant * 10) ?

function Formate() {
    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;
    }
}

mais il y a un bug car cela ne fonctionne pas correctement

Merci
Pascal

lundi 15 septembre 2008 à 16:16:29 | Re : Formater l'affichage d'un nombre

Skev

Réponse acceptée !
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);

lundi 15 septembre 2008 à 16:45:40 | Re : Formater l'affichage d'un nombre

oobox

Merci pour ta collaboration



Cette discussion est classée dans : affiche, nombre, formater, affichage, total


Répondre à ce message

Sujets en rapport avec ce message

Problème affichage du texte dans un datagrid [ par matoxik ] Bonjour, Alors voila, j'ai un xml connector,un dataset et et un datagrid reliés entre eux. Le problème est que le datagrid affiche normalment les donn Affichage du nombre de telechargement [ par LordDom ] Bonjour jaimerais savoir si il est possible avec flash d afficher le nombre de fois ou un bouton à été cliquéPar exemple le nombre de fois ou on a tel affichage d'un nombre d'éléments [ par touintils ] quii peut me donner un script ki permet d'af Affichage de symboles chinois dans flash [ par spix2rocker ] Bonjour à tous, bon pour ceux qui ont lu mon post sur la frise chronologique ou je galérais, ben j'ai trouvé ce matin. Donc bien contente. Seulement, Affichage - Tableau [ par Cath_ ] Bonjour,J'aimerais créer  un menu d'affichage (ex : comme un menu d'imprimante).  C'est un menu que pour naviguer à l'intérieur il faut appuyer sur de site flash qui ne s'affiche pas sous mozilla firefox [ par camillefly ] Bonjour a tous, Je viens de créer un site sous flash CS3 et il semblerait qu'il ne s'affiche pas sous mozilla firefox (page blanche) alors qu'il fonct Problème d'affichage diaporama en ligne [ par ssaze9 ] Salut à tous, J'ai un problème avec un petit diaporama que j'ai réalisé en mélangeant plusieurs source trouvé ici et là (enfin surtout ici! ). C'est u probléme avec décompte de la duré d'une vidéo [ par loblobloblob ] Bonjour,Aprés avoir réglé mes soucis de son ce matin (voir poste probléme de son rattaché a une vidéo) , j'aimerais faire un décompte de l le nombre de bytes téléchargés avec rtmp?????? [ par paris123321 ] salut à tous,    J'ai besoin de savoir le nombre de bytes téléchargés. Avec RTMP, on ne peut pas prendre "bytesLoaded". Il y a une autre solution?merc


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,716 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales