Jump to content

Is Numeric String?

Recommended Posts

Lucki you win on simplicity for sure.  But just to save a little bit of face I did a speed test and my method appears to be about 10 times faster on my I7 machine in LabVIEW 2013 SP1.


Of course our two methods don't always return the same result.  Yours considers NaN a number and depending on the application I could see wanting this feature or not, so I added it to mine.  Also your method accepts scientific notation like "4e6" where mine doesn't, and yours accepts imaginary numbers like "1 + 2i" where mine doesn't.


I never mentioned my application for this but I using this where a user can enter into a table some number.  The table is of course a string but it needs to be evaluated for being a number otherwise indicate it is formatted incorrectly.  In this case the user shouldn't ever think of entering NaN but if they do I'd consider that an invalid entry.  Same with "4e6", generally users will think in floating point and would type the extra zeros.  And users shouldn't enter imaginary numbers.  


Of course all these things are up to the developer to decide what types of input should be considered valid.

Link to comment

I think you should only accept the negative sign (-) to be at the beginning of the string. Right now it will accept "5-5" but that's not really a number...  :shifty:

Very good point, that isn't hard to add, just look evaluate the negative symbol only on the first iteration of the for loop.

Link to comment
  • 2 years later...

I ended up with issues after using this one for over a year because it ignores spaces before the number:


This is my version that allows NaN, Inf, -Inf to work and spaces are considered as a string.

.1 doesn't work, but a condition can be easily added.


Sorry for digging up an old thread, but this is the first link on Google and another thread would just get lost. This gives another alternative to the suggestions offered in this thread.

Edited by Stormshadow
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.