Convert strings with different format to float

Tom Kazimiers 2voodoo at gmx.de
Wed Sep 8 09:54:25 PDT 2010


Hi,

On 09/08/2010 10:02 AM, Stanislav Blinov wrote:
>> I would have thought that to!float() could handle a number without a
>> decimal point. If it can't I would suggest creating a bug report for
>> it. Now, since such a fix would not help you immediately in either
>> case, I would suggest creating a wrapper function which took a string
>> and then used to!int() for numbers without decimal points and
>> to!float() for number with them, and then returned a float. That way,
>> you wouldn't have to keep worrying about it. Also, you could try
>> parse(). It might be more forgiving.
>>
>> - Jonathan M Davis
>
> No it wouldn't :)
> It's indeed a bug, and it happens if string contains e.g. single 0
> (other digits are parsed normally). It seems that parse for floating
> points tries to determine if the number is in hex format, thus eating
> first 0, but it does not reuse this 0 later while it tries to pop next
> characters (and that results in assertion in std.array).

thanks for your answers. Indeed, it is a bug. As Don states no bug
report is needed, because it is fixed for a couple of weeks (in svn).

In the meantime (of waiting for upcoming release) I will, as Jonathan
suggested, create a wrapper function.

Cheers,
Tom


More information about the Digitalmars-d-learn mailing list