Stream: beginners

Topic: Decoding Decimals in Sqlite


view this post on Zulip 947R3K (Jan 13 2026 at 19:22):

I don't see a dedicated decoder for decimals in the Sqlite module docs. I also don't see a way to convert a different type of number to a decimal in roc's docs, so I'm a bit at a loss for how to store and retrieve decimal values from sqlite in roc.

view this post on Zulip 947R3K (Jan 14 2026 at 01:53):

I'll try to answer my own questions. There isn't a decimal decoder for Sqlite, but there is a U64 decoder. So as long as you don't need the full 128 bits of the Decimal type, you can decode a U64, use Num.to_u128 to cast to U128, then use Num.dec_from_bits to cast that to a Decimal.

view this post on Zulip Luke Boswell (Jan 14 2026 at 02:06):

Yeah I think it's a limitation in the old compiler - but probably not a priority to fix with the new compiler just around the corner.


Last updated: Feb 20 2026 at 12:27 UTC