This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Number format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Number format" Watch "Number format" New topic
Author

Number format

Dmitry Shekhter
Greenhorn

Joined: Feb 21, 2001
Posts: 26
I'm implementing the Comparator interface to compare two numeric values against each other. The values come in as a string consisting of 13 characters (ex: 2000102400001). I need to convert this string into a numeric value for comparison. Problem is the numeric formats I've tried(integer, long) throw a compile error "out of range". Any clues?
Thanks in advance.
Dmitry
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Check out the API for BigInteger, I'm sure you will find everything you need in there
Jason
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Use parseLong. Remember to enclose it within try/catch and catch NumberFormatException
long yourNum = Long.parseLong(yourString)

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Number format
 
Similar Threads
reading excel file using jdbc [help me]
How to get a String randomly?
String array generation with distinct values
Numberformat exception
Regular expression for numeric copy