comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Testing validity of numerical content of a string
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Testing validity of numerical content of a string [message #51824 is a reply to message #51744] Thu, 07 December 2006 09:43 Go to previous messageGo to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
Sven Geier wrote:
> In a pinch one might just force the conversion and catch any resulting
> error-messages with ON_ERROR -- that's ugly, but might be a lot easier than
> trying to parse strings...

So here's some code that does that:

function validate_numeric, value
compile_opt strictarr

on_ioerror, badValue

f = float(value)
return, 1B

badValue: return, 0B
end

The odd thing about this is what IDL will do without complaining. IDL
will do this without any error:

IDL> help, float('0.0hello5')
<Expression> FLOAT = 0.00000

but draws the line at:

IDL> help, float('hello5')
% Type conversion error: Unable to convert given STRING to Float.
% Detected at: $MAIN$
<Expression> FLOAT = 0.00000

Mike
--
www.michaelgalloy.com
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: creating MPEG in IDL
Next Topic: changing widget_button values can be very slow

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Tue Oct 21 05:48:20 PDT 2025

Total time taken to generate the page: 1.52030 seconds