Victor
Victor

Reputation: 17107

Netezza automatically rounding down decimal values

In Netezza, this expression automatically rounds down the result, how can I avoid that? I need to keep the original calculated value of 1.5, not 1

select cast ( (4 -1) / 2 AS NUMERIC (15,6)) as result --> gives 1.0000..

Upvotes: 1

Views: 5721

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 176004

Change one of arguments to NUMERIC to avoid integer division

SELECT (4 -1) / 2.0  AS result

or:

SELECT (4-1) / CAST(2 AS NUMERIC(15,6)) AS result

Division:

1 / 10   -> 0
1.0 / 10 -> 0.1
1 / 10.0 -> 0.1
1.0/10.0 -> 0.1

Upvotes: 2

Related Questions