ALLBASE/SQL Reference Manual (36216-90216)

216 Chapter7
Data Types
Decimal Operations
Decimal Operations
The precision (p) and scale (s) of a DECIMAL result depend on the operation used to derive
it. The following rules define the precision and scale that result from arithmetic operations
on two decimal values having precisions p
1
and p
2
and respective scales s
1
and s
2
. Rules
are also provided for the resulting precision and scale of aggregate functions that operate
on a single expression having a precision of p
1
and a scale of s
1
. Arithmetic operations and
aggregate functions are discussed further in Chapter 8 , “Expressions.
Addition and Subtraction
p = MIN(27, MAX (p
1
s
1
, p
2
s
2
) + MAX(s
1
, s
2
)+ 1)
s = MAX (s
1
,s
2
)
Multiplication
p = MIN (27, p
1
+ p
2
)
s = MIN (27, s
1
+ s
2
)
Division
p = 27
s = 27 MIN (27, p
1
s
1
+ s
2
)
where p
1
and s
1
describe the numerator operand, and p
2
and s
2
describe the denominator
operand.
MAX and MIN Functions
p = p
1
s = s
1
SUM Function
p = 27
s = s
1
AVG Function
p = 27
s = 27 p
1
+ s
1