Cet article est un article miroir de traduction automatique, veuillez cliquer ici pour accéder à l’article original.

Vue: 23890|Répondre: 1

[Source] String.Format the output {0 :N2} {0 :D2} {0 :C2

[Copié le lien]
Publié sur 26/04/2018 13:54:55 | | | |

//格式为sring输出
Label1.Text = chaîne. Format (« asdfadsf{0}adsfasdf »,a) ;
Label2.Text = « asdfadsf"+a.ToString()+"adsfasdf « ;
Label1.Text = chaîne. Format(« asdfadsf{0 :C}adsfasdf »,a) ; asdfadsf¥1,234.00adsfasdf
Label2.Text = « asdfadsf"+a.ToString(« C »)+"adsfasdf « ; asdfadsf¥1,234.00adsfasdf

   double b = 1234,12543 ;
   a = 12345678 ;
   Le format est une sortie spéciale de type chaîne
Label1.Text = chaîne. Format(« asdfadsf{0 :C}adsfasdf »,b) ; asdfadsf¥1,234.13ADSFASDF
Label2.Text = « asdfadsf"+b.ToString(« C »)+"adsfasdf « ; asdfadsf¥1,234.13ADSFASDF
Label1.Text = chaîne. Format(« {0 :C3} »,b) ; ¥1,234,125
Label2.Text = b.ToString(« C3 ») ; ¥1,234,125
Label1.Text = chaîne. Format(« {0 :d} »,a) ; Système décimal - 12345678
Label2.Text = b.ToString(« d ») ; Décimal - même type, erreur de conversion
Label1.Text = chaîne. Format(« {0 :e} »,a) ; Indice - 1,234568e+007
Label2.Text = b.ToString(« e ») ; Indice - 1,234125E+003

Label1.Text = chaîne. Format(« {0 :f} »,a) ; Nombre de points fixes - 12345678,00
Label2.Text = b.ToString(« f ») ; Numéro de point fixe - 1234,13
Label1.Text = chaîne. Format(« {0 :n} »,a) ; Valeur - 12 345 678,00
Label2.Text = b.ToString(« n ») ; Valeur - 1 234,13
Label1.Text = chaîne. Format(« {0 :x} »,a) ; HEX - BC614E
Label2.Text = b.ToString(« x ») ; 16 - Avec le nombre décimal impossible de convertir, une erreur a survenu
Label1.Text = chaîne. Format(« {0 :g} »,a) ; L’universel est le plus compact - 12345678
Label2.Text = b.ToString(« g ») ; Universal est le plus compact - 1234.12543
Label1.Text = chaîne. Format(« {0 :r} »,a) ; Retourner sans perdre de précision – les entiers ne sont pas autorisés à utiliser, les erreurs sont signalées
Label2.Text = b.ToString(« r ») ; Retourner sans perte de précision - 1234.12543
   
   b = 4321,12543 ;
   a = 1234 ;
   Sortie en mode personnalisé :
0 Description : Un espace provisoire, si possible, remplissez le bit
Label1.Text = chaîne. Format(« {0:00000} »,a) ; // 001234
Label2.Text = chaîne. Format(« {0:00000} »,b) ; // 004321
# Description : Un substitut, si possible, remplissez le bit
Label1.Text = chaîne. Format(« {0 :#######} »,a) ; // 1234
Label2.Text = chaîne. Format(« {0 :#######} »,b) ; // 4321
Label1.Text = chaîne. Format(« {0 :#0####} »,a) ; // 01234
Label2.Text = chaîne. Format(« {0:0#0000} »,b) ; // 004321

//   . Description : Virgule décimale
Label1.Text = chaîne. Format(« {0:000.000} »,a) ; //1234.000
Label2.Text = chaîne. Format(« {0:000.000} »,b) ; //4321.125
   b = 87654321,12543 ;
   a = 12345678 ;
, Description : Groupement numérique, également utilisé dans les multiplicateurs
Label1.Text = chaîne. Format(« {0:0,00} »,a) ; // 12,345,678
Label2.Text = chaîne. Format(« {0:0,00} »,b) ; // 87,654,32
Label1.Text = chaîne. Format(« {0:0,} »,a) ; // 12346
Label2.Text = chaîne. Format(« {0:0,} »,b) ; // 87654
Label1.Text = chaîne. Format(« {0:0,,} »,a) ; // 12
Label2.Text = chaîne. Format(« {0:0,,} »,b) ; // 88
Label1.Text = chaîne. Format(« {0:0,,,} »,a) ; // 0
Label2.Text = chaîne. Format(« {0:0,,,} »,b) ; 0 // % Description : Formatez en pourcentage // Label1.Text = chaîne. Format(« {0:0 %} »,a) ; 1234567800 % // Label2.Text = chaîne. Format(« {0 :# %} »,b) ; 8765432113 % // Label1.Text = chaîne. Format(« {0:0.00 %} »,a) ; 1234567800,00 % // Label2.Text = chaîne. Format(« {0 :#.00 %} »,b) ; 8765432112,54 % // 'abc' Description : Afficher le texte entre guillemets simples // Label1.Text = chaîne. format(« {0 :'text'0} »,a) ; Texte 12345678 // Label2.Text = chaîne. format(« {0 :text 0} »,b) ; Texte 87654321 // / Description : 1 suivi du caractère à imprimer, également utilisé pour transférer le caractère /n etc. // Label1.Text = chaîne. Format (« /"Bonjour ! /""); « Bonjour ! » Label2.Text = chaîne. Format (« //c//livres//nouveau//we.asp ») ; c/books/new/we.asp // @描述 : suivi du caractère à imprimer, // Label1.Text = chaîne. Format(@"""""Bonjour ! """); « Bonjour ! » Pour imprimer, il faut entrer deux paires pour // Label2.Text = chaîne. Format(@"/c/books/new/we.asp ») ; c/books/new/we.asp Le format en pourcentage doit utiliser le paramètre « p ».  Formater Résultat brut des données « {0 :P} » 0,40 40 %

Numéro {0 :N2} 12,36  
Nombre {0 :N0} 13  
Monnaie {0 :c2} 12,36 $  
Monnaie {0 :c4} 12,3656 $  
Monnaie « ¥{0 :N2} » ¥12,36  
Notation scientifique {0 :E3} 1.23E+001  
Pourcentage {0 :P} 12,25 % P et p présentent le même.
Date {0 :D} 25 novembre 2006  
Date {0 :d} 2006-11-25  
Date {0 :f} 10:30, 25 novembre 2006 (UTC)  
Date {0 :F} 10:30:00, 25 novembre 2006 (UTC)  
Date {0 :s} 2006-11-26 10:30:00  
Heure {0 :T} 10:30:00

DateTimeDt = DateTime.Now ;
Label1.Text = dt. ToString() ; //2005-11-5 13:21:25
Label2.Text = dt. ToFileTime(). ToString() ; //127756416859912816
Label3.Text = dt. ToFileTimeUtc(). ToString() ; //127756704859912816
Label4.Text = dt. ToLocalTime(). ToString() ; //2005-11-5 21:21:25
Label5.Text = dt. ToLongDateString(). ToString() ; 5 novembre 2005
Label6.Text = dt. ToLongTimeString(). ToString() ; //13:21:25
Label7.Text = dt. ToOADate(). ToString() ; //38661.5565508218
Label8.Text = dt. ToShortDateString(). ToString() ; //2005-11-5
Label9.Text = dt. ToShortTimeString(). ToString() ; //13:21
Label10.Text = dt. VersTempsUniversel(). ToString() ; //2005-11-5 5:21:25

Label1.Text = dt. Year.ToString() ; //2005
Label2.Text = dt. Date.ToString() ; //2005-11-5 0:00:00
Label3.Text = dt. DayOfWeek.ToString() ; Samedi
Label4.Text = dt. DayOfYear.ToString() ; //309
Label5.Text = dt. Heure.ToString() ; //13
Label6.Text = dt. Milliseconde.ToString() ; //441
Label7.Text = dt. Minute.ToString() ; //30
Label8.Text = dt. Mois.À String() ; //11
Label9.Text = dt. Deuxième.ToString() ; 28 Label10.Text = dt. Ticks.ToString() ; 632667942284412864 Label11.Text = dt. TimeOfDay.ToString() ; 13:30:28.4412864 Label1.Text = dt. ToString() ; 2005-11-5 13:47:04 Label2.Texte = dt. AddYears(1). ToString() ; 2006-11-5 13:47:04 Label3.Text = dt. AddDays(1.1). ToString() ; 2005-11-6 16:11:04 Label4.Text = dt. AddHours(1.1). ToString() ; 2005-11-5 14:53:04 Label5.Text = dt. AddMillisecondes(1,1). ToString() ; 2005-11-5 13:47:04 Label6.Texte = dt. AjoutMois(1). ToString() ; 2005-12-5 13:47:04 Label7.Texte = dt. AddSeconds(1.1). ToString() ; 2005-11-5 13:47:05 Label8.Text = dt. AddMinutes(1.1). ToString() ; 2005-11-5 13:48:10 Label9.Texte = dt. AddTicks (1000). ToString() ; 2005-11-5 13:47:04 Label10.Texte = dt. CompareTo(dt). ToString() ; 0 Label11.Text = dt. Ajouter ( ?). ToString() ; Le point d’interrogation est un point temporel Label1.Text = dt. Égal (« 2005-11-6 16:11:04 »). ToString() ; Fausse étiquette2.Texte = dt. Égal (dt). ToString() ; True Label3.Text = dt. GetHashCode(). ToString() ; 1474088234 Label4.Text = dt. GetType(). ToString() ; System.DateTime Label5.Text = dt. GetTypeCode(). ToString() ; DateHeure Label1.Texte = dt. GetDateTimeFormats('s')[0]. ToString() ; 2005-11-05T14:06:25 Label2.Text = dt. GetDateTimeFormats('t')[0]. ToString() ; 14:06 Label3.Text = dt. GetDateTimeFormats('y')[0]. ToString() ; Novembre 2005 Label4.Text = dt. GetDateTimeFormats('D')[0]. ToString() ; 5 novembre 2005 Label5.Text = dt. GetDateTimeFormats('D')[1]. ToString() ; 2005 11 05 Label6.Texte = dt. GetDateTimeFormats('D')[2]. ToString() ; Samedi 2005 11 05 Label7.Texte = dt. GetDateTimeFormats('D')[3]. ToString() ; Samedi 5 novembre 2005 Label8.Text = dt. GetDateTimeFormats('M')[0]. ToString() ; 5 novembre Label9.Text = dt. GetDateTimeFormats('f')[0]. ToString() ; 14:06, 5 novembre 2005 Label10.Texte = dt. GetDateTimeFormats('g')[0]. ToString() ; 2005-11-5 14:06 Label11.Texte = dt. GetDateTimeFormats('r')[0]. ToString() ; Sam, 05 nov 2005 14:06:25 GMT Label1.Text = chaîne. Format(« {0 :d} »,dt) ; 2005-11-5 Label2.Text = chaîne. Format(« {0 :D} »,dt) ; 5 novembre 2005 Label3.Text = chaîne. Format(« {0 :f} »,dt) ; 14:23, 5 novembre 2005 Label4.Text = chaîne. Format(« {0 :F} »,dt) ; 14:23:23, 5 nov. 2005 Label5.Text = chaîne. Format(« {0 :g} »,dt) ; 2005-11-5 14:23 Label6.Text = chaîne. Format(« {0 :G} »,dt) ; 2005-11-5 14:23:23 Label7.Texte = chaîne. Format(« {0 :M} »,dt) ; 5 novembre Label8.Text = chaîne. Format(« {0 :R} »,dt) ; Sam, 05 nov. 2005 14:23:23 GMT Label9.Text = chaîne. Format(« {0 :s} »,dt) ; 2005-11-05T14:23:23 Étiquette 10.Chaîne de texte. Format(« {0 :t} »,dt) ; 14:23 Label11.Texte = chaîne. Format(« {0 :T} »,dt) ; 14:23:23 Label12.Text = chaîne. Format(« {0 :u} »,dt) ; 2005-11-05 14:23:23Z Label13.Text = chaîne. Format(« {0 :U} »,dt) ; 05/01/2005 6:23:23 AM Label14.Texte = chaîne. Format(« {0 :Y} »,dt) ; Novembre 2005 Label15.Text = chaîne. Format(« {0} »,dt) ; 2005-11-5 14:23:23 Label16.Text = chaîne. Format(« {0 :yyyMMddHHmmssffff} »,dt) ;
stringstr1 = stringstr. Format(« {0 :N1} »,56789) ;                Résultat : 56 789,0
stringstr2 = stringstr. Format(« {0 :N2} »,56789) ;                résultat : 56 789,00
stringstr3 =string. Format(« {0 :N3} »,56789) ;                résultat : 56 789 000
stringstr8 =string. Format(« {0 :F1} »,56789) ;                Résultat : 56789,0
stringstr9 =string. Format(« {0 :F2} »,56789) ;                Résultat : 56789,00
stringstr11 =(56789 / 100.0). ToString(« #.## ») ;            Résultat : 567,89
stringstr12 =(56789 / 100). ToString(« #.## ») ;              Résultat : 567

C ou C
Monnaie
Console.Write(« {0 :C} », 2.5) ;   2,50 $
Console.Write(« {0 :C} », -2.5) ; (2,50 $)

D ou d
Nombres décimaux
Console.Write(« {0 :D5} », 25) ;   //00025

E ou E
Type scientifique
Console.Write(« {0 :E} », 250000) ;   2,500000E+005

F ou F
Point fixe
Console.Write(« {0 :F2} », 25) ;   //25.00
Console.Write(« {0 :F0} », 25) ;   //25

G ou G
Régulier
Console.Write(« {0 :G} », 2.5) ;   //2.5

n ou n
Nombres
Console.Write(« {0 :N} », 2500000) ;   //2,500,000.00

X ou X
Système hexagonal
Console.Write(« {0 :X} », 250) ;   FA
Console.Write(« {0 :X} », 0xffff) ;   FFFF




Précédent:Téléchargement de l’installateur Xposed v3.1.5 / Framework version 90
Prochain:Apprenez Photoshop à partir de zéro, 18 leçons du novice au dieu
 Propriétaire| Publié sur 26/04/2018 13:57:10 |
Démenti:
Tous les logiciels, supports de programmation ou articles publiés par Code Farmer Network sont uniquement destinés à l’apprentissage et à la recherche ; Le contenu ci-dessus ne doit pas être utilisé à des fins commerciales ou illégales, sinon les utilisateurs assumeront toutes les conséquences. Les informations sur ce site proviennent d’Internet, et les litiges de droits d’auteur n’ont rien à voir avec ce site. Vous devez supprimer complètement le contenu ci-dessus de votre ordinateur dans les 24 heures suivant le téléchargement. Si vous aimez le programme, merci de soutenir un logiciel authentique, d’acheter l’immatriculation et d’obtenir de meilleurs services authentiques. En cas d’infraction, veuillez nous contacter par e-mail.

Mail To:help@itsvse.com