Heim  >  Artikel  >  Backend-Entwicklung  >  String-Format für Double in C#

String-Format für Double in C#

PHPz
PHPznach vorne
2023-09-11 11:29:02773Durchsuche

C# 中 Double 的字符串格式

Verwenden Sie die statische Methode String.Format in C#, um ein Doppelstringformat zu bilden.

Für drei Dezimalstellen -

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

Für Tausendertrennzeichen -

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

Formatzeichenfolge -

Beispiel

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));
   }
}

Das obige ist der detaillierte Inhalt vonString-Format für Double in C#. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:tutorialspoint.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen