'Snowflake DIV0 returns different result than regular division
Why are these results different, comparing Snowflake division vs DIV0? It appears DIV0 is rounding down instead of up. Is there any way to make the DIV0 return the same number as the other results?
Snowflake query:
SELECT 75026 / 99999 AS divide_by,
DIV0(75026, 99999) AS div_0,
NVL(75026 / NULLIF(99999, 0), 0) AS div_nvl
Snowflake result:
DIVIDE_BY DIV_0 DIV_NVL
0.750268 0.750267 0.750268
Calculator result:
0.7502675026750268
Solution 1:[1]
Another way you can implement NVL based approach
set num=75026;
set den=0;
select iff($den=0,0,$num/$den)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Phil Coulson |
