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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version