C# Double ToString()

Description

Double ToString() converts the numeric value of this instance to its equivalent string representation.

Syntax

Double.ToString() has the following syntax.


public override string ToString()

Returns

Double.ToString() method returns The string representation of the value of this instance.

Example

The following example uses the default Double.ToString() method to display the string representations of a number of Double values.


using System;/* w  w  w.  j  a  va  2s.  c o  m*/
public class MainClass{
  public static void Main(String[] argv){  
    double number;
    
    number = 1.6E20;
    Console.WriteLine(number.ToString());
    
    number = 1.6E2;
    Console.WriteLine(number.ToString());
    
    number = -3.541;
    Console.WriteLine(number.ToString());
    
    number = -1234567892199E-07;
    Console.WriteLine(number.ToString());
    
    number = -12345678921990199574E-09;
    Console.WriteLine(number.ToString());
    
    number = .12344;
    Console.WriteLine(number.ToString());
    
    number = .000000001;
    Console.WriteLine(number.ToString());

   
  }
}

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