Number-to-number conversion

When you need to convert one numeric data type into another one, you must pay attention to the differences between these data types and ensure that the receiving data type is able to store all the value. When converted, given values are transformed so as to that it can be stored as the target data type. For example, when you convert DECIMAL values to the INTEGER data type, decimal places will be discarded, and the data stored in them will be lost.

 

Conversion doesn't only produce wrong results sometimes - it can fail as well. For example, conversion will fail, if you try to convert a FLOAT value with more than 8 significant digits into the SMALLFLOAT data type or if you try to convert an INTEGER value larger than 32,767 into SMALLINT.

 

You may get an overflow if you try to convert FLOAT or SMALLFLOAT values to INTEGER, SMALLINT, or DECIMAL data types. For example, converting a FLOAT value into the DECIMAL data type may result in overflow, underflow, or cause rounding errors, because a floating-point number must be rounded off before it could be stored as a fixed-point number.

INTEGER-to-DECIMAL conversion

TINYINT, SMALLINT, INTEGER, and BIGINT values will be converted to SMALLFLOAT, FLOAT, DECIMAL, or

MONEY correctly if the receiving variable has a sufficient number of digits to hold the whole original value:

MAIN

DEFINE d DECIMAL(10, 2),

       i INTEGER

 

LET i = 12345

LET d = i

DISPLAY d -- will return 12345.00

 

CALL fgl_getkey()

END MAIN

If the original value exceeds the range of the receiving data type, you will get an overflow.

DECIMAL-to-INTEGER conversion

When SMALLFLOAT, FLOAT, DECIMAL, or MONEY values are converted into TINYINT, SMALLINT, INTEGER, and BIGINT, the fractional part of the decimal value is truncated:

MAIN

DEFINE d DECIMAL(10, 2),

       i INTEGER

 

LET d = 123.45

LET i = d

DISPLAY i -- will return 123

 

CALL fgl_getkey()

END MAIN

If the original value exceeds the range of the receiving integer data type, you will get an overflow.

DECIMAL-to-DECIMAL conversion

Conversion between SMALLFLOAT, FLOAT, DECIMAL, or MONEY will be correct if the receiving variable has a sufficient number of digits to hold the whole original value:

MAIN

DEFINE d1 DECIMAL(10, 2),

       d2 DECIMAL(5, 1)

 

LET d1 = 123.45

LET d2 = d1

DISPLAY d2 -- will return 123.5

 

CALL fgl_getkey()

END MAIN

If the original value has more fractional digits than the receiving data type supports, all the low-order digits will be discarded.

 

Contact Us

Privacy Policy

Copyright © 2026 Querix, (UK) Ltd.