Results 1 to 4 of 4
Thread: using numberformat
- 07-01-2009, 08:52 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 6
- Rep Power
- 0
using numberformat
Hi ,
I am trying to use number format in java to achieve the same functionality of that of Integer.parseInt(String s)
String s = "845";
int x = Integer.parseInt(s);
System.out.println(x);
NumberFormat formatter = NumberFormat.getNumberInstance();
Number n = formatter.parse(s); // I get an error here.
What is the issue here. So how do we use numberformat to get the same function?
- 07-01-2009, 09:20 PM #2
tryNumber parse(String source) - Parses text from the beginning of the given string to produce a number.
Long x = (Long) formatter.parse("123");
EDIT:
what kind of error? did you catch the exception?Last edited by angryboy; 07-01-2009 at 09:28 PM.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 07-02-2009, 04:13 AM #3
Member
- Join Date
- Jul 2009
- Posts
- 6
- Rep Power
- 0
works now
Hi,
It works now as you pointed it out. I was not catching the ParseException as well.
Thanks,
Rohan.
- 07-02-2009, 04:28 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you have solve the problem please mark it as solved from the thread tools menu. It's really helpful to all other members. :)
Similar Threads
-
NumberFormat is abstract?
By DrKush in forum New To JavaReplies: 4Last Post: 03-27-2009, 07:54 AM -
Parsing a number using a NumberFormat
By Java Tip in forum java.textReplies: 0Last Post: 04-16-2008, 11:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks