Re: calculated values in sql: extending the decimal
Posted in 1997
On Wed, 17 Dec 1997, Nelson Fredsell wrote:
> I'm dividing one number into another. Both numbers have 4 decimals,
> but the caluculated value has only 2 decimals. I would like the
> calculated value to also have 4 decimal places. How do I do this?
>
> select (table_a.col_a + table_a.col_b) / table_b.col_a pct
> from table_a, table_b
> where table_a.col_c = table_b.col_c
Assuming you are using either DB-Access or ISQl, the answer is to set the
environment variable DBFLTMASK=6 to get 6 decimal places, as in:
CREATE TEMP TABLE t
(
col_a DECIMAL(8,4) NOT NULL,
col_b DECIMAL(8,4) NOT NULL,
col_c DECIMAL(8,4) NOT NULL
);
INSERT INTO t VALUES(1.2345, 3.4567, 5.6789);
SELECT (col_a + col_b) / col_c AS value FROM t;
value
0.826075
Yours,
Jonathan Leffler (johnl@informix.com) #include <witticism.h>