Format double value to use Numeric ("N") Format Specifier in CSharp
Description
The following code shows how to format double value to use Numeric ("N") Format Specifier.
Example
using System;/* w w w . j av a 2s .c om*/
using System.Globalization;
public class MainClass {
static void Main()
{
double dblValue = -12445.6789;
Console.WriteLine(dblValue.ToString("N", CultureInfo.InvariantCulture));
// Displays -12,445.68
Console.WriteLine(dblValue.ToString("N1",
CultureInfo.CreateSpecificCulture("sv-SE")));
// Displays -12 445,7
int intValue = 123456789;
Console.WriteLine(intValue.ToString("N1", CultureInfo.InvariantCulture));
// Displays 123,456,789.0
}
}
The code above generates the following result.