HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to DelphiVariablesData Types & ConversionOperatorsStringsConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔄 Data Types & Conversion
✍️ String
🔁 Condition & Loop
🧩 Function & Procedure
Delphi›Data Types & Conversion

Data Types & Conversion

Basic types and number ↔ text conversion with IntToStr / StrToInt (SysUtils).

Simple enough for a 5-year-old to understand

StrToInt / IntToStr

StrToInt converts text to number, IntToStr converts number to text. Requires uses SysUtils;.

Example code
1
program H;
2
{$MODE DELPHI}
3
uses SysUtils;
For conversion functions.
ImportFor conversion functions.
4
begin
5
writeln(StrToInt('40') + 2);
Convert text to number: 42
Output / InputConvert text to number: 42
6
writeln('Age: ' + IntToStr(36));
Number to text: Age: 36
Output / InputNumber to text: Age: 36
7
end.
ImportOutput / Input
💡 Hint: Conversion functions are in the SysUtils unit; don't forget to add uses SysUtils;.

About this topic

Delphi's type system is rich: integers of various widths, floating-point numbers, a special type for currency, characters, text, and boolean values. The range of each type is documented, and the compiler catches mismatches.

Having a separate type for monetary calculations stems from Delphi's business application heritage. Because floating-point types cannot perfectly represent decimal fractions, penny drift occurs in financial amounts; the special type solves this issue with a fixed-decimal internal representation.

The text type has changed across versions. Before Delphi 2009, it was single-byte; afterwards, it is Unicode-based. When migrating legacy code, this difference leads to corruption in Turkish characters and is the most common migration issue.

What you will learn

  • Integer types and ranges
  • Floating-point and currency types
  • Text and character types
  • Type conversion functions
  • Record and array types

Who is this for?

  • Those doing financial calculations
  • Those migrating legacy code to Unicode
  • Those getting overflow errors

When to use?

A currency type or a type offering decimal precision should be used anywhere dealing with money amounts; amounts kept in floating-point types drift as they are accumulated.

Defining record types that match database fields is a way to document data structure in code and catch type errors at compile time.

Common mistakes

Wrong

var
  tutar: Double;
  i: Integer;
begin
  tutar := 0;
  for i := 1 to 10 do
    tutar := tutar + 0.1;
  if tutar = 1.0 then
    writeln('exact')
  else
    writeln('not exact');
end.

Floating-point numbers cannot perfectly represent decimal fractions in binary base; when one-tenth is added ten times, the result does not equal one and the comparison fails. In financial and precise decimal calculations, the currency type must be used, and floating-point values should never be compared with equality.

Correct

var
  tutar: Currency;
  i: Integer;
begin
  tutar := 0;
  for i := 1 to 10 do
    tutar := tutar + 0.1;
  if tutar = 1.0 then
    writeln('exact')
  else
    writeln('not exact');
end.

Wrong

var
  deger: Integer;
begin
  deger := 2147483647;
  deger := deger + 1;
  writeln(deger);
end.

When the upper limit of an integer type is exceeded, the value wraps around and becomes negative. Overflow checking can be enabled via compiler settings, but it is disabled in the default release configuration. When working with large values, you need to choose a wider type.

Correct

var
  deger: Int64;
begin
  deger := 2147483647;
  deger := deger + 1;
  writeln(deger);
end.

Wrong

var
  sayi: Integer;
begin
  sayi := StrToInt('abc');
  writeln(sayi);
end.

The conversion function throws an exception on invalid input and the program crashes. For user-provided data, it is necessary to use the safe version that returns a default value or the try version that reports success status.

Correct

var
  sayi: Integer;
begin
  sayi := StrToIntDef('abc', 0);
  writeln(sayi);
end.

Frequently asked questions

Which integer type should I choose?

For general use, the platform-width default type is appropriate. If the value range can exceed two billion, you should switch to a sixty-four-bit type. Unless there are memory constraints, bothering with smaller types rarely provides any benefit.

What is the difference between floating-point and currency types?

Floating-point types work with binary fractions and introduce rounding errors in decimal values; the currency type is stored as an integer with a fixed four decimal places. In financial totals, the latter gives the correct result.

What is the difference between a record type and a class?

Records are value types: they are copied upon assignment and you do not need to allocate memory for them. Classes are reference types: they are created, used, and freed. For small data groups, records are simpler and safer.

Summary

A special currency type is used in monetary calculations.

Floating-point values are not compared using equality.

Integer overflow silently wraps around.

Conversion functions have safe versions.

Records are value types, classes are reference types.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code