No, I don't think this is right? You are using Floats and as per my
previous rant on this, there are a lot of issues with the default
rounding on floats
I haven't used the decimal library in anger, but I would expect you to
need to use the Decimal.to_string function and checking the code implies
you would first need to update the rounding to the correct decimal
places you want for display.
Actually, this seems a bit ugly, I wonder if Eric might not accept a
formatting patch to improve this? It would need additional options to
accept decimal places (and/or sig figures) and then (after some
arithmetic) trim the digit list to the correct length. Edit: I see you
might also need to pad the list with zeros
I was previously quite pleased with my "stringify" function here. It
effectively takes a string of digits, such as the internal list that
Eric's library is maintaining, and prints them out in various formats
with the decimal in the right place:
https://github.com/ewildgoose/elixir-float_pp/blob/master/lib/float_pp.ex
Please don't use that whole project directly, it was an attempt add
adding correct pretty printing of arbitrary floats. Eric's library
includes the important meat of this, plus various rounding and
arithmetic options. However, my formatting code looks more capable,
perhaps you could rip that out and send him a patch..?
Ed W