ToText Inconsistencies

A question for the engineers probably (if it hasn’t been already answered – I couldn’t find it doing a search):
Integer.FromText throws a bad data exception if the text passed is not a number.
Double.FromText and Single.FromText don’t – they return a 0 if they were not successful.

Is that inconsistency chosen by design or by mistake?
And if the first: What is the reason?

Thanks!

[quote=304109:@Ulrich Bogun]Is that inconsistency chosen by design or by mistake?
[/quote]

This sounds like a bug.

Thanks, Joe!
feedback://showreport?report_id=46359

[quote]Integer.FromText throws a bad data exception if the text passed is not a number.
Double.FromText and Single.FromText don’t – they return a 0 if they were not successful.[/quote]

Didn’t we have a major strop about this a year or two back with the new framework?
With several people saying there was nothing wrong with Val() which returns 0 for bad numbers, and
Xojo saying ‘no, we want to generate an exception which you will have to trap’

On that basis, Double.FromText and Single.FromText would seem be the ones that were ‘buggy’.
I’d be happy for them all to return 0

if your text is “0” then you could catch it as an error if they were all returning 0 for a bad number, dont you ?

I think what I remember from the discussions was that ToText returns a value if it is a number. Zero is a number. Not a number should trigger an exception. Some said that they wished ToText worked more like Val() which can perfectly well accept for instance
“123 objects” and return 123.

Which is why they added integer(double, etc).Parse to behave like Val.
http://developer.xojo.com/integer$Parse

I would like to see an IsValidDouble function that can be used to test a text string before trying to convert it.

If IsValidDouble(myChunkOfText) then
  dim myDouble as double = myChunkOfText.FromText
Else
  'Handle bad numeric text
End if

And of course an IsValidInteger, etc.

http://developer.xojo.com/isnumeric in classic framework.

Thanks Michel. I had searched for such a function but nothing came up. (I tried looking for IsNumber.)

If IsNumeric(myChunkOfText) then
  dim myDouble as double = myChunkOfText.FromText
Else
  'Handle bad numeric text
End if