C# Double ToString(String, IFormatProvider)
Description
Double ToString(String, IFormatProvider)
converts
the numeric value of this instance to its equivalent string representation
using the specified format and culture-specific format information.
Syntax
Double.ToString(String, IFormatProvider)
has the following syntax.
public string ToString(
string format,
IFormatProvider provider
)
Parameters
Double.ToString(String, IFormatProvider)
has the following parameters.
format
- A numeric format string.provider
- An object that supplies culture-specific formatting information.
Returns
Double.ToString(String, IFormatProvider)
method returns The string representation of the value of this instance as specified by format
and provider.
Example
The following example displays a Double value using each of the supported standard numeric format specifiers for several different cultures.
using System;/*from ww w . j a v a2 s. c om*/
using System.Globalization;
public class MainClass{
public static void Main(String[] argv){
double value = 12345.67891;
string specifier;
CultureInfo culture;
// Use standard numeric format specifiers.
specifier = "G";
culture = CultureInfo.CreateSpecificCulture("eu-ES");
Console.WriteLine(value.ToString(specifier, culture));
Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture));
specifier = "C";
culture = CultureInfo.CreateSpecificCulture("en-US");
Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("en-GB");
Console.WriteLine(value.ToString(specifier, culture));
specifier = "E04";
culture = CultureInfo.CreateSpecificCulture("sv-SE");
Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("en-NZ");
Console.WriteLine(value.ToString(specifier, culture));
specifier = "F";
culture = CultureInfo.CreateSpecificCulture("fr-FR");
Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("en-CA");
Console.WriteLine(value.ToString(specifier, culture));
specifier = "N";
culture = CultureInfo.CreateSpecificCulture("es-ES");
Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("fr-CA");
Console.WriteLine(value.ToString(specifier, culture));
specifier = "P";
culture = CultureInfo.InvariantCulture;
Console.WriteLine((value/10000).ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("ar-EG");
Console.WriteLine((value/10000).ToString(specifier, culture));
}
}
The code above generates the following result.