首頁  >  文章  >  後端開發  >  C# 中 Double 的字串格式

C# 中 Double 的字串格式

PHPz
PHPz轉載
2023-09-11 11:29:02773瀏覽

C# 中 Double 的字符串格式

在 C# 中使用靜態方法 String.Format 形成雙字串格式。

對於三位小數 -

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

對於千位元分隔符號 -

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

格式化字串 -

範例

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

以上是C# 中 Double 的字串格式的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除