Reputation: 1080
Is there a method that takes in a float string and converts it to a single float. It must also handle strings without .
like "1"
String.to_float
does not handle "1"
iex(5)> String.to_float("1")
** (ArgumentError) argument error
:erlang.binary_to_float("1")
iex(5)> String.to_float("1.0")
1.0
Float.parse
handles "1"
, but returns a tuple.
iex(4)> Float.parse("1")
{1.0, ""}
Upvotes: 1
Views: 724
Reputation: 44
Maybe you should use something like
{res, _} = Float.parse("1")
or
elem Float.parse("1"), 0
Upvotes: 3