C# Convert ToString(Int32, IFormatProvider)
Description
Convert ToString(Int32, IFormatProvider)
converts
the value of the specified 32-bit signed integer to its equivalent string
representation, using the specified culture-specific formatting information.
Syntax
Convert.ToString(Int32, IFormatProvider)
has the following syntax.
public static string ToString(
int value,
IFormatProvider provider
)
Parameters
Convert.ToString(Int32, IFormatProvider)
has the following parameters.
value
- The 32-bit signed integer to convert.provider
- An object that supplies culture-specific formatting information.
Returns
Convert.ToString(Int32, IFormatProvider)
method returns The string representation of value.
Example
The following example defines a custom NumberFormatInfo class that defines its negative sign as the string "~" and its positive sign as the string "!".
/* w ww. j a v a 2 s . com*/
using System;
public class MainClass{
public static void Main(String[] argv){
int[] numbers = { Int32.MinValue, Int32.MaxValue};
System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
nfi.NegativeSign = "~";
nfi.PositiveSign = "!";
foreach (int number in numbers)
Console.WriteLine("{0,-12} --> {1,12}",
Convert.ToString(number, System.Globalization.CultureInfo.InvariantCulture),
Convert.ToString(number, nfi));
}
}
The code above generates the following result.