Home >Backend Development >C#.Net Tutorial >String format for Double in C#
Use the static method String.Format in C# to form a double string format.
For three decimal places -
String.Format("{0:0.000}", 987.383); String.Format("{0:0.000}", 987.38); String.Format("{0:0.000}", 987.7899);
For thousands separator -
String.Format("{0:0,0.0}", 54567.46); String.Format("{0:0,0}", 54567.46);
Format string -
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)); } }
The above is the detailed content of String format for Double in C#. For more information, please follow other related articles on the PHP Chinese website!