Posted by Eugene, Nov. 11, 2022, 6:27 a.m.
Weird sensitivity to decimal points
Hi!
I noticed some pretty funky sensitivity out in the 9th/10th decimal places in some problems. Queestion #114 is an example. My code is below - seems to generate the right answer, but the console marks it as wrong - only difference seems to be out in the 9th/10th decimal place. Maybe better practice would be to edit the question to explicitly ask for set number of decimal points to avoid confusion?
-- Question 114 -> marked wrong by console --
with cte_1 AS (
select
o.order_dt,
sum(o.qty*o.unit_price_usd) as revenue
from orders o
group by 1)
select
order_dt,
(revenue - LAG(revenue,1) OVER ( order by order_dt asc))::numeric* 100 /
(LAG(revenue,1) OVER (order by order_dt asc))::numeric as dod_change
from cte_1
order by 1 asc