Division

From InterBase
Jump to: navigation, search

Go Up to Exact Numerics (Language Reference Guide)


If both operands are exact numeric, dividing the operands produces an exact numeric with a precision of 18 and a scale equal to the sum of the scales of the operands. If at least one operand of a division operator has an approximate numeric type (FLOAT, REAL, or DOUBLE PRECISION), the result is DOUBLE PRECISION.

For example, in the following table, division operations produce a variety of results:

CREATE TABLE t1 (i1 INTEGER), i2 INTEGER, n1 NUMERIC(16,2)
n2 NUMERIC(16,2));
INSERT INTO t1 VALUES (1, 3, 1.00, 3.00);
COMMIT;

The following query returns the integer 0 because each operand has a scale of 0, so the sum of the scales is 0:

SELECT i1/i2 FROM t1

The following query returns the NUMERIC(18,2) value 0.33, because the sum of the scales 0 (operand 1) and 2 (operand 2) is 2:

SELECT i1/n2 FROM t1

The following query returns the NUMERIC(18,4) value 0.3333, because the sum of the two operand scales is 4:

SELECT n1/n2 FROM t1

In InterBase 5 and earlier, any of the above division operations would have returned the DOUBLE PRECISION value 0.3333333333333333.