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

AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14403 124
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
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
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement