Converting from number to number

When you convert data from one number data type to another, you occasionally find rounding errors.

The following table indicates which numeric data type conversions are acceptable and what kinds of errors you can encounter when you convert between certain numeric data types. In the table, the following codes are used:

OK
No error
P
An error can occur, depending on the precision of the decimal
E
An error can occur, depending on the data value
D
No error, but less significant digits might be lost
Table 1. Acceptable conversions and possible errors

This table shows acceptable datatype conversions and conversions that might cause errors.

Target Type SMALL INT INTEGER INT8 SMALL FLOAT FLOAT DECIMAL
SMALLINT OK OK OK OK OK OK
INTEGER E OK OK E OK P
INT8 E E OK D E P
SMALLFLOAT E E E OK OK P
FLOAT E E E D OK P
DECIMAL E E E D D P

For example, if you convert a FLOAT value to DECIMAL(4,2), your database server rounds off the floating-point number before storing it as DECIMAL.

This conversion can result in an error depending on the precision assigned to the DECIMAL column.