Thousand Separator Program in C#

In this tutorial, we will learn how to separate the value with thousand separator using C# program? By IncludeHelp Last updated : April 09, 2023

Thousand Separator for a Number

To print a number with thousand separators in C#, we can use String.Format() function with digits placeholder (#) and commas. Below are the syntaxes of custom strings for thousand separators with and without decimal points,

// With decimal point
String.Format("{0:0,0.0}", 987654321.67)

// Wihtout decimal point
String.Format("{0:0,0}", 987654321.67)

C# program for thousand separator of a number

using System;

namespace ConsoleApplication1 {
  class Program {
    static void Main(string[] args) {
      //Thousand separator
      Console.WriteLine("Thousand Separators");

      Console.WriteLine(String.Format("{0:0,0.0}", 9876.67));
      Console.WriteLine(String.Format("{0:0,0}", 9876.67));
      Console.WriteLine(String.Format("{0:0,0.0}", 987654321.67));
      Console.WriteLine(String.Format("{0:0,0}", 987654321.67));

      Console.WriteLine();
    }
  }
}

Output

Thousand Separators
9,876.7
9,877
987,654,321.7
987,654,322



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.