C# Int64 ToString(String)

Description

Int64 ToString(String) converts the numeric value of this instance to its equivalent string representation, using the specified format.

Syntax

Int64.ToString(String) has the following syntax.


public string ToString(
  string format
)

Parameters

Int64.ToString(String) has the following parameters.

  • format - A numeric format string.

Returns

Int64.ToString(String) method returns The string representation of the value of this instance as specified by format.

Example

The following example displays an Int64 value using each of the supported standard numeric format specifiers together with two custom numeric format strings.


/*from w  w  w  .  j a  va2s . co  m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    long value = -12345;
    string specifier;
    
    // Use standard numeric format specifier.
    specifier = "G";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "C";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "D8";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "E4";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "e3";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "F";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "N";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "P";
    Console.WriteLine("{0}: {1}", specifier, (value/100000.0).ToString(specifier));
    
    specifier = "X";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    // Use custom numeric format specifiers.
    specifier = "0,0.000";
    Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
    
    specifier = "#,#.00#;(#,#.00#)";
    Console.WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier));

  }
}

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