Bug - Won't Fix is_numeric() returns false for decimals.

Bale

Minion
Since to_float("123.4") returns 123.4 without giving an error, shouldn't is_numeric("123.4") return true? This seems like a bug to me.

Code:
[COLOR="#808000"]> ash is_numeric("123.4")[/COLOR]

Returned: false

[COLOR="#808000"]> ash is_numeric("1234")[/COLOR]

Returned: true

[COLOR="#808000"]> ash to_float("1234")[/COLOR]

Returned: 1234.0

[COLOR="#808000"]> ash to_float("123.4")[/COLOR]

Returned: 123.4

[COLOR="#808000"]> ash to_float("123a4")[/COLOR]

The string "123a4" is not a float; returning 0.0 ()
Returned: 0.0
 
Last edited by a moderator:

StDoodle

Minion
I have an RFI up on the wiki regarding this function. It parses + / - at the front of a string for an integer, but as Bale mentioned, decimal points cause "false" to be returned. Perhaps the function should be renamed "is_integer()"?
 

Veracity

Developer
Staff member
I'm willing to name is_numeric to is_integer...

In fact, I have done so in revision 8314.

A function which returns true on either an integer or a float might help you decide whether you can call to_float() on the string without error, but the function as provided was intended to let you decide whether you could call to_int() on it without a stack trace.

Therefore, renaming it seems the correct solution.
 
Last edited:

Bale

Minion
Thanks.

I have an RFI up on the wiki regarding this function.

I actually posted this bug report because I noticed your RFI. Every now and then I click on a few of them at random and try to answer your questions, but that RFI belonged here.
 

StDoodle

Minion
I've had a couple I'd like to post here, but I already make a fool of myself with unreproducible bug reports often enough. ;)

Anything with an unanswerable RFI should probably go on here eventually, but I wanted to give everything some time in case I was just missing something, so I didn't spam the bug report forum with ash questions.
 
Top