C# Decimal ToString(String, IFormatProvider)
Description
Decimal 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
Decimal.ToString(String, IFormatProvider)
has the following syntax.
public string ToString(
string format,
IFormatProvider provider
)
Parameters
Decimal.ToString(String, IFormatProvider)
has the following parameters.
format
- A numeric format string (see Remarks).provider
- An object that supplies culture-specific formatting information.
Returns
Decimal.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 Decimal value using each of the supported standard numeric format specifiers for several different cultures.
using System;/*w w w. j a v a 2 s . c o m*/
using System.Globalization;
public class MainClass{
public static void Main(String[] argv){
decimal value = 12345.67m;
string specifier;
CultureInfo culture;
// Use standard numeric format specifiers.
specifier = "G";
culture = CultureInfo.CreateSpecificCulture("eu-ES");
System.Console.WriteLine(value.ToString(specifier, culture));
System.Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture));
specifier = "C";
culture = CultureInfo.CreateSpecificCulture("en-US");
System.Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("en-GB");
System.Console.WriteLine(value.ToString(specifier, culture));
specifier = "E04";
culture = CultureInfo.CreateSpecificCulture("sv-SE");
System.Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("en-NZ");
System.Console.WriteLine(value.ToString(specifier, culture));
specifier = "F";
culture = CultureInfo.CreateSpecificCulture("fr-FR");
System.Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("en-CA");
System.Console.WriteLine(value.ToString(specifier, culture));
specifier = "N";
culture = CultureInfo.CreateSpecificCulture("es-ES");
System.Console.WriteLine(value.ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("fr-CA");
System.Console.WriteLine(value.ToString(specifier, culture));
specifier = "P";
culture = CultureInfo.InvariantCulture;
System.Console.WriteLine((value/10000).ToString(specifier, culture));
culture = CultureInfo.CreateSpecificCulture("ar-EG");
System.Console.WriteLine((value/10000).ToString(specifier, culture));
}
}
The code above generates the following result.