Netezza自动舍入小数值

时间:2015-12-14 18:18:43

标签: sql casting netezza

在Netezza中,此表达式自动舍入结果,我该如何避免?我需要保持原始计算值1.5,而不是1

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

1 个答案:

答案 0 :(得分:1)

将一个参数更改为NUMERIC以避免整数除法

SELECT (4 -1) / 2.0  AS result

或:

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

司:

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