C# Convert ToString(Decimal, IFormatProvider)
Description
Convert ToString(Decimal, IFormatProvider)
converts
the value of the specified decimal number to its equivalent string representation,
using the specified culture-specific formatting information.
Syntax
Convert.ToString(Decimal, IFormatProvider)
has the following syntax.
public static string ToString(
decimal value,
IFormatProvider provider
)
Parameters
Convert.ToString(Decimal, IFormatProvider)
has the following parameters.
value
- The decimal number to convert.provider
- An object that supplies culture-specific formatting information.
Returns
Convert.ToString(Decimal, IFormatProvider)
method returns The string representation of value.
Example
The following example converts each element in an array of Decimal values to its equivalent string representation in four different cultures.
//from w w w. j av a2s . c o m
using System;
public class MainClass{
public static void Main(String[] argv){
decimal[] numbers = { 123123123.16m, -17394.32921m,
3193.23m, 123123123.684m };
// Define the culture names used to display them.
string[] cultureNames = { "en-US", "fr-FR", "ja-JP", "ru-RU" };
foreach (decimal 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));
}
}
}
}
The code above generates the following result.