[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] Empty string .asInteger returns 0

On Dec 29, 2013 7:45 PM, "Eirik Arthur Blekesaune" <eirik.blekesaune@xxxxxxxxx> wrote:
> Why does "".asInteger return 0? Wouldn't it be more correct to return nil?
> Same goes for "".asInt btw?

I think, if you're converting a string to an integer, you should get an integer back. Nil isn't an integer, so...

The precedent is the atoi() function in C:


"If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed and zero is returned."