Number comparisons
1 posts in topic
Flat View  Flat View

Posted By:   Scott_Abernathy
Posted On:   Monday, May 7, 2001 09:54 AM

In Javascript, we use isNAN to check whether the character passed is a number, what can we use in Java to check wheter the passed is a number or not?

Re: Number comparisons

Posted By:   AlessandroA_Garbagnati  
Posted On:   Monday, May 7, 2001 10:32 AM


Try to convert that string in a number. If it fails, then it's not a number:

int num;
try {

 &nspnum = Integer.parseInt(MyString);


catch (NumberFormatException nfE) {

  // handle the error


Or, if it's just a char, you can do this:

public boolean isANumber(char c) {

  return ((c >= '0') && (c <= '9'));

About | Sitemap | Contact