'Workaround for Redshift ROUND function and floating point approximations
No solution needed. Writing this because i do not have enough reputation to reply here: Redshift ROUND function doesn't round in some cases?
Occasionally, the ROUND function will not actually round as intended. For example:
SELECT ROUND(176::FLOAT / 492::FLOAT,4)
will return 0.35769999999999996. A coworker shared this workaround where you round to the unit digit and multiply/divide by 10 to the power of places after the decimal:
SELECT ROUND(10000 * 176 / 492) / 10000.0
which will return the expected 0.3577.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
