`CSV.encode` float values are automatically converted scientific notation

CSV.encode float values are automatically converted scientific notation

When I do CSV.encode(7900.00)
I get ["7.9e3\r\n"]
instead of ["7900.00\r\n"]

I’ve checked CSV docs (v3.2.1) and CSV code but I can’t figure out how to correctly avoid this format conversion.
I’m using elixir 1.14.2-otp-25
Any suggestions?
Thanks in advance


Resolved with

defimpl CSV.Encode, for: Float do
  def encode(data, _env \\ []) do
    data |> Float.to_string(decimals: 2)
  end
end
5 Likes