Delphi's Object Pascal is a strongly typed language. That means, that every variable must be
declared and that the compiler will check the
type of all the variables before the compilation of your program. Without this feature, many errors would only
appear at run-time, making them much harder to debug.
A simple example:
var
I: integer;
begin
I := 0.5;
...results in an error message: Incompatible types: 'integer' and 'Extended'
In Delphi, there are 3 groups of numbers:
- integer numbers
- floating point numbers (have a decimal fraction)
- fixed point numbers (for financial calculations)
Delphi's most important number types are:
Type |
Range |
Integer types
Byte
ShortInt
Word
SmallInt
Cardinal
Integer
Int64
Floating point types
Single
Double
Extended
Real: same as Double
Fixed point types
Currency
|
0 to 255
-127 to 127
0 to 65,535
-32,768 to 32,767
0 to 4,429,967,295
-2,147,483,648 to 2,147,483,647
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
7 significant digits, exponent -38 to 38
15 significant digits, exponent -308 to 308
19 significant digits, exponent -4932 to 4932
15 significant digits, exponent -308 to 308
50 significant digits, 4 fixed decimal places
|
Some functions for integer types:
Function |
Meaning |
Examples |
Pred(I)
Succ(I)
High(Type)
Low(Type)
|
Predecessor of I
Successor of I
Highest value of a type
Lowest value of a type
|
Pred(10) returns 9
Succ(10) returns 11
High(Byte) returns 255
Low(Byte) returns 0
|
Some procedures for integer types:
Procedure |
Meaning |
Examples |
Inc(I)
Dec(I)
|
Increment I
Decrement I
|
Inc(I) is equivalent to I := I+1
Dec(I) is equivalent to I := I-1
|
Some functions for floating point types that return Int64 values:
Function |
Meaning |
Examples |
Round(X)
Trunc(X)
|
Round X to the nearest
integer number (down or up)
Truncate decimal fraction of X
|
Round(1.4) returns 1
Round(1.6) returns 2
Trunc(1.6) returns 1
|
Functions to convert numbers to strings that can be displayed:
Function |
Meaning |
Examples |
IntToStr(I)
IntToHex(I, W)
FloatToStrF(N, F, P, D)
CurrToStrF(N, F, D)
|
Conversion of integer I
to string
Hexadecimal representation
of integer I in width W
Conversion of N in format F
precision P and D digits
Conversion of currency N
in format F and D digits
|
IntToStr(10) returns '10'
IntToHex(43, 3) returns '02B'
FloatToStrF(Pi, ffFixed, 6, 5)
returns '3.14159'
CurrToStrF(3.25, ffFixed, 2)
returns '3.25'
|
Terms used in the table above:
- Format can be:
- ffFixed: fixed point format, in the form "-ddd.ddd..."
- ffNumber: number format, in the form "-d,ddd,ddd.ddd...". Same as ffFixed format,
except that the result contains thousandth separators.
- ffGeneral: general number format, the shortest possible decimal string using scientific format
- ffExponent: scientific format, in the form "-d.ddd...E+dddd"
- ffCurrency: currency format, controlled by the global variables that
are initialized from Currency Format in the International section of the Windows Control Panel.
- Precision: length of the decimal fraction
- Digits: total number of significant digits in the result
|
|