Returns a string representation of the value of the current instance.
- format
- A string that specifies the format of the returned string.
A string representation of the current instance formatted as specified by format. The string takes into account the current system culture.
Type Reason FormatException format is invalid.
This version of decimal.ToString is equivalent to decimal.ToString (format , null ).
If format is a null reference, the general format specifier "G" is used.
The following example shows the effects of various formats on the string returned by decimal.ToString.
C# Example
using System; class test { public static void Main() { decimal d = 1234.56789m; Console.WriteLine(d); string[] fmts = {"C","E","F","G","N","P"}; for (int i=0;i<fmts.Length;i++) Console.WriteLine("{0}: {1}", fmts[i],d.ToString(fmts[i])); } }The output is
1234.56789
C: $1,234.57
E: 1.234568E+003
F: 1234.57
G: 1234.56789
N: 1,234.57
P: 123,456.79 %
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0