Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
bglaplante
Contributor III
Contributor III

mathematical.NUM clarification

the documentation for mathematical.NUM says it checks if the string in numeric.

So - if it is Integer (i.e. only 0-9 digits)?

How about with a decimal point? Ex 4.9809 ?

How about scientific notation 2.3E-9 ?

How about with comma: 5,230 ?

It isn't clear what 'numeric' is. My main concern is with decimal point in v 7.3. The other questions are just for completeness.

Labels (2)
3 Replies
Anonymous
Not applicable

Hi

Look into the source code of this function.

 public static int NUM(String e) {

    if (e.matches("\\d+")) { //$NON-NLS-1$

      return 1;

    }

    return 0;

  }

 

the function check the string if it only contains 0-9 digits.

 

Regards

Shong

bglaplante
Contributor III
Contributor III
Author

Well, that's a pity it doesn't see 99.95 as a number. Or -9 as a number either! Definite documentation update needed.

gjeremy1617088143

Hi maybe you can use something like this

 

((your_String) != null && (your String).length()>0 && !(your String).replaceAll("(^-?\\d+$)|(^-?\\d+\\.\\d*$)","").isEmpty())

 

return true if your string is not null and not empty and the value of the string is

-(optionnal) + some digits(one ore more)

or

-(optionnal) + some digits(one or more) followed by a dot followed by some digits (one or more)

 

it will match :

10

-10

10.34

-10.34

for exemple.

 

 

you can also write a routine method like this one if you want to use Double for eg:

 

public static boolean isNumeric(String strNum) {

if (strNum == null) {

return false;

}

try {

double d = Double.parseDouble(strNum);

} catch (NumberFormatException nfe) {

return false;

}

return true;

}

 

 

Send me love and kudos