munksgaard

munksgaard

Adding support for Decimal in Explorer

I am working with monetary data, for which floats are largely discouraged. As a result, I am using the fairly popular Decimal package and the associated Ecto support to store monetary values in my database and process them in my app.

I’m also a big fan of Livebook and Explorer to process my data. However, Explorer does not currently have support for Decimals, which means that I have to manually convert to floats, losing all the benefits of working with Decimal in the first place.

Therefore, I am wondering what it would take to add support for Decimals to Explorer, and whether anyone is working on such support already. If not, how would such a task even be completed? Would we need to add support directly in the Explorer library, or could some sort of external plugin be enough? Would anyone else be interested in this?

Most Liked

billylanchantin

billylanchantin

Follow-up: We did end up adding decimal support via Decimal.

  • Add support for the decimals data type.

    Decimals dtypes are represented by the {:decimal, precision, scale} tuple, where precision can be a positive integer from 0 to 38, and is the maximum number of digits that can be represented by the decimal. The scale is the number of digits after the decimal point.

    With this addition, we also added the :decimal package as a new dependency. The Explorer.Series.from_list/2 function accepts decimal numbers from that package as values - %Decimal{}.

    This version has a small number of operations, but is a good foundation.

LostKobrakai

LostKobrakai

Explorer doesn‘t use elixir datatypes. It uses a rust library to deal with data in raw binary form. For explorer to support fixed precision numbers the underlying rust library would need to support those. Or you convert to integers at the precision you need.

billylanchantin

billylanchantin

Hi @munksgaard,

@LostKobrakai is right. We rely on the Polars library under the hood. So my first instinct is no, we won’t be able to support the Decimal library.

However, it may be worth making an issue on Explorer anyway. Polars has support for a decimal datatype:

We add new data types relatively frequently, and this may be worth pursuing. The tricky part would be figuring out how we represent things on the Elixir side. But it’s certainly possible.

Where Next?

Popular in Discussions Top

New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20046 166
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18584 126
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New

Other popular topics Top

jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement