list_to_float
Dmitriy Kargapolov
dmitry.kargapolov@REDACTED
Wed Aug 9 20:23:14 CEST 2006
As I understand the name "list_to_float" means conversion _to_ float
(not integer!) from _some_ list representation.
The current implementation is limited to string only argument - this is
reasonable, but it's not clear why implementation is limited to narrow
X.X representation? Couldn't float be expressed as "0"?
As to list_to_number idea, what type of result is expected? Depending on
argument text representation?
James Hague wrote:
> Actually list_to_number would be a good standard library addition. It would
> call list_to_integer first, then if that failed, call list_to_float.
>
> -----Original Message-----
> From: owner-erlang-bugs@REDACTED [mailto:owner-erlang-bugs@REDACTED] On
> Behalf Of Håkan Stenholm
> Sent: Wednesday, August 09, 2006 12:56 PM
> To: Demius Academius
> Cc: erlang-bugs@REDACTED
> Subject: Re: list_to_float
>
> Demius Academius wrote:
>
>> list_to_float("0") exited with badarg
>> it must work as list_to_float("0.0")
>>
> you'll have to do something like:
>
> str_to_float(Str) ->
> try float(list_to_integer(Str))
> catch error:_ -> list_to_float(Str)
> end.
>
> or
>
> str_to_float(Str) ->
> case string:to_float(Str) of
> {error, no_float} ->
> {Int, []} = case string:to_integer(Str),
> float(Int);
> {Float, []} -> Float
> end.
>
> as "0" is considered a integer(), while "0.0" is treated as a float().
> But I agree that it would be much nicer if list_to_float/1 and
> string:to_float/1 would do this by themselves.
>
More information about the erlang-bugs
mailing list