Page 1 sur 1

[RESOLU]Formater facilement "1000000" => "1 000 000"

Publié : 15 Juin 2018 19:47
par JohnyBoy
Bonjour

Existe t-il un moyen facile et efficace avec les string.format ou tostring("quelque chose ici") pour formater un nombre à 6 ou + chiffres ?

J'ai essayé deux trois trucs mais ça ne donne pas grand chose.

Exemple

Code : Tout sélectionner

int value = 1000000;

text.text = value.tostring();

text.text retourne alors "1000000";
Moi j'aimerais que la chaîne retourne "1 000 000";

Re: Formater facilement "1000000" => "1 000 000"

Publié : 15 Juin 2018 21:26
par Alesk
Tu devrais trouver ton bonheur ici :
https://docs.microsoft.com/fr-fr/dotnet ... at-strings

Re: Formater facilement "1000000" => "1 000 000"

Publié : 15 Juin 2018 21:28
par Autodidactelife
Bonjour, une simple recherche sur google permet facilement de trouver ça:

Code : Tout sélectionner

using System.Globalization;

Code : Tout sélectionner

int value = 1000000;
value.ToString("n", new CultureInfo("fr-FR"));
Ce qui nous sort "1 000 000,00".

Exemple: https://msdn.microsoft.com/fr-fr/librar ... .110).aspx

Cordialement

Re: Formater facilement "1000000" => "1 000 000"

Publié : 16 Juin 2018 17:13
par JohnyBoy
Super merci beaucoup :super: