[Solved] Formatting double values for display


You can use N format specifier as;

double salary = 12345.6789;
Console.WriteLine(salary.ToString("N2"));

Result will be;

12,345.68

This specifier uses your CurrentCulture‘s NumberGroupSeparator and NumberDecimalSeparator properties by default. If these properties are not , and . in your CurrentCulture, you can provide InvariantCulture to this .ToString() method as a second parameter like;

double salary = 12345.6789;
Console.WriteLine(salary.ToString("N2", CultureInfo.InvariantCulture));

solved Formatting double values for display