Description |
The ToString method concerts the current Int16 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 Int16 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.Int16
|
|
|
Examples of the various formattings |
program Project1;
{$APPTYPE CONSOLE}
var
valueA : Int16;
begin
valueA := 1234;
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.
| Show full unit code | Default = 1234
C : Currency = ?1,234.00
D : Integer = 1234
E : Scientific = 1.234000E+003
F : Fixed = 1234.00
G : General = 1234
N : Numeric = 1,234.00
P : Percent = 123,400.00 %
X : Hex = 4D2
| | Using the optional precision parameter | program Project1;
{$APPTYPE CONSOLE}
var
valueA : Int16;
begin
valueA := 1234;
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.
| Show full unit code | Default = 1234
C : Currency = ?1,234.000000
D : Integer = 001234
E : Scientific = 1.234000E+003
F : Fixed = 1234.000000
G : General = 1234
N : Numeric = 1,234.000000
P : Percent = 123,400.000000 %
X : Hex = 0004D2
|
|
|
|