| Author |
Verify if a String is numeric
|
Rafael Afonso
Ranch Hand
Joined: Jul 16, 2002
Posts: 63
|
|
Hello: I find that this is a pparently silly doubt (so I am writing in beginner's forum): I never found a method in the API of the Java to verify if a String is numerical or not, either Integer or floating-point. A way - that I don't like - would be to make something thus: Other way - that does not use exception - would be thus: In that if it relates to the floating-point numbers (float and double), still we must take in consideration the point decimal, that varies of locale for locale ("," in Brazil, "." in U.S.A., for example). At last, is there only these alternatives above, that we must construct "manually"? Somebody has some idea? Thanks,
|
=================================<br /> Rafael U. C. Afonso<br /> <a href="http://www.javafree.com.br" target="_blank" rel="nofollow">www.javafree.com.br</a><br />=================================<br /><i>Where is debug?<br />debug is on the table</i>
|
 |
Adrian Airloy
Greenhorn
Joined: Dec 31, 2002
Posts: 11
|
|
Hey Rafael If I was checking if a String was an int or not, I would tend to use the 'valueOf' method in the Integer class. And extract the appropriate int value from it or throw an exception. However if you are only intrested in checking if a String is an int or not (as a boolean response), then what you have written above appears to be right. [ March 08, 2003: Message edited by: Adrian Miranda ]
|
SCJP.<br />I haven't lost my mind, it's backed up on a disk somewhere!
|
 |
Rafael Afonso
Ranch Hand
Joined: Jul 16, 2002
Posts: 63
|
|
Adrian: From your suggestion, the first code would be thus: It does not make difference to final goal. But thanks anyway.
|
 |
John Smith
Ranch Hand
Joined: Oct 08, 2001
Posts: 2937
|
|
In that if it relates to the floating-point numbers (float and double), still we must take in consideration the point decimal, that varies of locale for locale ("," in Brazil, "." in U.S.A., for example). At last, is there only these alternatives above, that we must construct "manually"? Somebody has some idea?
I think what you looking for is this: Eugene.
|
 |
 |
|
|
subject: Verify if a String is numeric
|
|
|