C# Single ToString(IFormatProvider)
Description
Single ToString(IFormatProvider)
converts the numeric
value of this instance to its equivalent string representation using the
specified culture-specific format information.
Syntax
Single.ToString(IFormatProvider)
has the following syntax.
public string ToString(
IFormatProvider provider
)
Parameters
Single.ToString(IFormatProvider)
has the following parameters.
provider
- An object that supplies culture-specific formatting information.
Returns
Single.ToString(IFormatProvider)
method returns The string representation of the value of this instance as specified by provider.
Example
The following example displays the string representation of two Single values using CultureInfo objects that represent several different cultures.
using System.Globalization;
using System;/* w w w . j ava 2s .com*/
public class MainClass{
public static void Main(String[] argv){
float value = -12345.12345F;
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")));
value = 12345.123E21F;
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")));
}
}
The code above generates the following result.