How to separate number thousands in C#?
To separate a number every thousands in C#, we can useNumberFormatInfo
part of using System.Globalization;
namespace, and set property NumberGroupSeparator
with any delimiter we want.Example
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
var nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
nfi.NumberGroupSeparator = ",";
string formatted = 2231456.11m.ToString("#,0.00", nfi); //
Console.WriteLine(formatted);
}
}
Output
2,231,456.11