Format double to a easy-parse format with Round-trip ("R") Format Specifier in CSharp
Description
The following code shows how to format double to a easy-parse format with Round-trip ("R") Format Specifier.
Example
using System;/* ww w . ja v a 2s.co m*/
using System.Globalization;
public class MainClass {
static void Main()
{
double value;
value = Math.PI;
Console.WriteLine(value.ToString("r"));
// Displays 3.1415926535897931
Console.WriteLine(value.ToString("r",
CultureInfo.CreateSpecificCulture("fr-FR")));
// Displays 3,1415926535897931
value = 1.623e-21;
Console.WriteLine(value.ToString("r"));
// Displays 1.623E-21
}
}
The code above generates the following result.