I have some strings that represent numbers. The only catch is, I don't know ahead of time whether they contain a decimal point or not.
iex(12)> String.to_integer("45")
45
iex(13)> String.to_integer("45.0")
** (ArgumentError) argument error
:erlang.binary_to_integer("45.0")
iex(11)> String.to_float("45.0")
45.0
iex(11)> String.to_float("45")
** (ArgumentError) argument error
:erlang.binary_to_float("45")
I could write a string_to_num function that checks the string to see if it contains a period and then use the appropriate String.to_X function, but that seems very clumsy.
Any pointers on how to handle this would be appreciated.
Thanks,
Elliot