C# Convert ToString(Double, IFormatProvider)
Description
Convert ToString(Double, IFormatProvider)
converts
the value of the specified double-precision floating-point number to its
equivalent string representation.
Syntax
Convert.ToString(Double, IFormatProvider)
has the following syntax.
public static string ToString(
double value,
IFormatProvider provider
)
Parameters
Convert.ToString(Double, IFormatProvider)
has the following parameters.
value
- The double-precision floating-point number to convert.provider
- An object that supplies culture-specific formatting information.
Returns
Convert.ToString(Double, IFormatProvider)
method returns The string representation of value.
Example
The following example converts each element in an array of Double values to its equivalent string representation in four different cultures.
//w w w. j a v a 2 s .co m
using System;
public class MainClass{
public static void Main(String[] argv){
double[] numbers = { -1.5345e16, -123.4321, 19092.123, 1.1734231911290e16 };
string[] cultureNames = { "en-US", "fr-FR", "ja-JP", "ru-RU" };
foreach (double number in numbers)
{
Console.WriteLine("{0}:", Convert.ToString(number,
System.Globalization.CultureInfo.InvariantCulture));
foreach (string cultureName in cultureNames)
{
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cultureName);
Console.WriteLine(" {0}: {1,20}",
culture.Name, Convert.ToString(number, culture));
}
Console.WriteLine();
}
}
}
The code above generates the following result.