C# Decimal ToString()
Description
Decimal ToString()
converts the numeric value of this
instance to its equivalent string representation.
Syntax
Decimal.ToString()
has the following syntax.
public override string ToString()
Returns
Decimal.ToString()
method returns A string that represents the value of this instance.
Example
The following example displays a Decimal value using the default ToString() method. It also displays the string representations of the Decimal value that result from using a number of standard format specifiers.
using System;//from w w w .ja v a2s .c o m
public class MainClass{
public static void Main(String[] argv){
decimal value = -16325.62m;
// Display value using default ToString method.
System.Console.WriteLine(value.ToString()); // Displays -16325.62
// Display value using some standard format specifiers.
System.Console.WriteLine(value.ToString("G")); // Displays -16325.62
System.Console.WriteLine(value.ToString("C")); // Displays ($16,325.62)
System.Console.WriteLine(value.ToString("F")); // Displays -16325.62
}
}
The code above generates the following result.