Maison  >  Article  >  développement back-end  >  Format de chaîne pour Double en C#

Format de chaîne pour Double en C#

PHPz
PHPzavant
2023-09-11 11:29:02773parcourir

C# 中 Double 的字符串格式

Utilisez la méthode statique String.Format en C# pour former un format de chaîne double.

Pour trois décimales -

String.Format("{0:0.000}", 987.383);
String.Format("{0:0.000}", 987.38);
String.Format("{0:0.000}", 987.7899);

Pour le séparateur de milliers -

String.Format("{0:0,0.0}", 54567.46);
String.Format("{0:0,0}", 54567.46);

Format de la chaîne -

Exemple

using System;

class Demo {

   public static void Main(String[] args) {
      Console.WriteLine("Three decimal places...");
   
      Console.WriteLine( String.Format("{0:0.000}", 987.383));
      Console.WriteLine( String.Format("{0:0.000}", 987.38));
      Console.WriteLine(String.Format("{0:0.000}", 987.7899));
   
      Console.WriteLine("Thousands Separator...");
      Console.WriteLine(String.Format("{0:0,0.0}", 54567.46));
      Console.WriteLine(String.Format("{0:0,0}", 54567.46));
   }
}

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer