Home > Backend Development > C#.Net Tutorial > String format for Double in C#

String format for Double in C#

PHPz
Release: 2023-09-11 11:29:02
forward
923 people have browsed it

C# 中 Double 的字符串格式

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);
Copy after login

For thousands separator -

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

Format string -

Example

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));
   }
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template