C# Printing a float number with thousand separators using String.Format() method

C# String.Format() strategy example: Here, we will figure out how to print a buoy number with thousand separators utilizing String.Format() technique in C#?

To print a buoy number with thousand separators, we can utilize String.Format() strategy, here is the example.

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

Leave a Comment

error: Alert: Content is protected!!