Home  |  Delphi .net Home  |  System.Int64  |  ToString Method
  
ToString  
Method  
Converts the current Int64 value to a string
Int64 Structure
System NameSpace
CF1.  Function ToString : String;
CF2.  Function ToString ( Formatting : String ) : String;
CF3.  Function ToString ( Formatting : String; FormatProvider : IFormatProvider ) : String;
CF4.  Function ToString ( FormatProvider : IFormatProvider ) : String;
CF : Methods with this mark are Compact Framework Compatible
Description
The ToString method concerts the current Int64 value into a string representation.
 
By default, with no parameters, it is equivalent to ToString('G') - 'General' formatting is carried.
 
The Formatting string (or array of strings) provides the desired formatting of the Int64 value.
 
The formatting value has the following syntax :
 
FormattingChar[Precision]
 
The formatting character can be one of the following values :
 
C or c Currency such as ?1,234.56
D or d Integer formatting such as 123456
E or e Exponential (Scientific) such as 1.23456E+003
F or f Fixed Point such as 1234.56
G or g General : type dependent
N or n Number : -d,ddd,ddd.ddd... format
P or p Percent such as 69.5%
R or r Round-trip - guarantees reverse formatting
X or x Hex such as E06FC (using X) or e06fc (using x)

 
The FormatProvider parameter determines the parsing rules and is beyond the scope of this article.
Notes
ToString without parameters is a method inherited from the base System.Object (TObject) class. It provides a ready method for classes to convert their content into a string format.
Microsoft MSDN Links
System
System.Int64
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Examples of the various formattings
program Project1;
{$APPTYPE CONSOLE}

var
  valueA : Int64;

begin
  valueA := 1234567890;

  Console.WriteLine('    Default    = {0}', valueA.ToString);
  Console.WriteLine('C : Currency   = {0}', valueA.ToString('C'));
  Console.WriteLine('D : Integer    = {0}', valueA.ToString('D'));
  Console.WriteLine('E : Scientific = {0}', valueA.ToString('E'));
  Console.WriteLine('F : Fixed      = {0}', valueA.ToString('F'));
  Console.WriteLine('G : General    = {0}', valueA.ToString('G'));
  Console.WriteLine('N : Numeric    = {0}', valueA.ToString('N'));
  Console.WriteLine('P : Percent    = {0}', valueA.ToString('P'));
  Console.WriteLine('X : Hex        = {0}', valueA.ToString('X'));

  Console.ReadLine;
end.
       Default    = 1234567890
   C : Currency   = ?1,234,567,890.00
   D : Integer    = 1234567890
   E : Scientific = 1.234568E+009
   F : Fixed      = 1234567890.00
   G : General    = 1234567890
   N : Numeric    = 1,234,567,890.00
   P : Percent    = 123,456,789,000.00 %
   X : Hex        = 499602D2
Using the optional precision parameter
program Project1;
{$APPTYPE CONSOLE}

var
  valueA : Int64;

begin
  valueA := 1234567890;

  Console.WriteLine('    Default    = {0}', valueA.ToString);
  Console.WriteLine('C : Currency   = {0}', valueA.ToString('C6'));
  Console.WriteLine('D : Integer    = {0}', valueA.ToString('D6'));
  Console.WriteLine('E : Scientific = {0}', valueA.ToString('E6'));
  Console.WriteLine('F : Fixed      = {0}', valueA.ToString('F6'));
  Console.WriteLine('G : General    = {0}', valueA.ToString('G6'));
  Console.WriteLine('N : Numeric    = {0}', valueA.ToString('N6'));
  Console.WriteLine('P : Percent    = {0}', valueA.ToString('P6'));
  Console.WriteLine('X : Hex        = {0}', valueA.ToString('X6'));

  Console.ReadLine;
end.
       Default    = 1234567890
   C : Currency   = ?1,234,567,890.000000
   D : Integer    = 1234567890
   E : Scientific = 1.234568E+009
   F : Fixed      = 1234567890.000000
   G : General    = 1.23457E+09
   N : Numeric    = 1,234,567,890.000000
   P : Percent    = 123,456,789,000.000000 %
   X : Hex        = 499602D2
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author