Numeric Conversions

The available numeric conversions depend on the datatype characteristics.

Table 1. Datatype Conversions

Datatype

Converts to

Comments

NUMERIC or DECIMAL

SIGNED INTEGER

A NUMERIC or DECIMAL datatype with scale 0 can be converted into a SIGNED INTEGER, provided the precision required to represent the maximum value of the integer is greater than or equal to the precision of the NUMERIC or DECIMAL datatype.

NUMERIC or DECIMAL

INTEGER

NUMERIC or DECIMAL datatypes with a scale other than zero cannot be converted into an integer, and numerics cannot be converted into unsigned integers.

NUMERIC or DECIMAL

Other NUMERIC or DECIMAL datatypes

A NUMERIC or DECIMAL datatype can be converted into other numeric or decimal types, provided that the scale of the target type is greater than or equal to the scale of the source numeric, and the precision of the target numeric is greater than or equal to the precision of the source numeric plus the difference between the target scale and the source scale.

Examples

Use examples as a reference for some of the available conversions.

Example 1

NUMERIC(4, 2) can be converted into a NUMERIC(4, 4)
NUMERIC(2, 2) can be converted into a NUMERIC(4, 4)
NUMERIC(2, 4) cannot be converted into a NUMERIC(4, 0)
NUMERIC(2, 4) cannot be converted into a NUMERIC(3, 6)


Created March 26, 2009. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com