FirebirdSQL logo

NUMERIC

Data Type Declaration Format
NUMERIC [(precision [, scale])]
Table 1. NUMERIC Type Parameters
Parameter Description

precision

Precision, between 1 and 38.Defaults to 9.

scale

Scale, between 0 and precision.Defaults to 0.

Storage Examples

Further to the explanation above, Firebird will store NUMERIC data according the declared precision and scale.Some more examples are:

NUMERIC(4) stored as      SMALLINT (exact data)
NUMERIC(4,2)              SMALLINT (data * 102)
NUMERIC(10,4) (Dialect 1) DOUBLE PRECISION
              (Dialect 3) BIGINT (data * 104)
NUMERIC(38,6)             INT128 (data * 106)
Caution

Always keep in mind that the storage format depends on the precision.For instance, you define the column type as NUMERIC(2,2) presuming that its range of values will be -0.99…​0.99.However, the actual range of values for the column will be -327.68…​327.67, which is due to storing the NUMERIC(2,2) data type in the SMALLINT format.In storage, the NUMERIC(4,2), NUMERIC(3,2) and NUMERIC(2,2) data types are the same.This means that if you need to store data in a column with the NUMERIC(2,2) data type and limit the range to -0.99…​0.99, you will have to create a CHECK constraint for it.

DECIMAL

Data Type Declaration Format
{ DECIMAL | DEC } [(precision [, scale])]
Table 1. DECIMAL Type Parameters
Parameter Description

precision

Precision, between 1 and 38.Defaults to 9.

scale

Scale, between 0 and precision.Defaults to 0.

Storage Examples

The storage format in the database for DECIMAL is similar to NUMERIC, with some differences that are easier to observe with the help of some more examples:

DECIMAL(4) stored as      INTEGER (exact data)
DECIMAL(4,2)              INTEGER (data * 102)
DECIMAL(10,4) (Dialect 1) DOUBLE PRECISION
              (Dialect 3) BIGINT (data * 104)
DECIMAL(38,6)             INT128 (data * 106)