[Proposal] parse float with leading dot

34 views
Skip to first unread message

Alessandro Di Maria

unread,
Oct 2, 2020, 7:18:41 AM10/2/20
to elixir-lang-core

Hello

I would like to open a PullRequest that would allow parsing floats with a leading dot.

Current situation:

iex> Float.parse(".25")
:error

Suggested:

iex> Float.parse(".25)
{0.25, ""}

I detected this behavior in a form that uses LiveView. The form has an input field for a float, on change a new calculation is triggered.
When a user now wants to changes the value from "8.0" to "9.0" he may delete first the "8", leaving the field with ".0". This blew up my LiveView.

I forked the repo, and made the changes already, all tests are passing so far.

Alessandro

José Valim

unread,
Oct 2, 2020, 8:52:38 AM10/2/20
to elixir-l...@googlegroups.com
We discussed this in the past and we decided to only parse floats supported by the language itself. Luckily this case is easy to address within your own projects by checking if the string starts with a dot and then adding a leading 0.

In any case, thanks for asking and have a good weekend!

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/c1944f60-18d4-4317-90d7-c43bcd2024een%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages