Java NumberFormatException

Posted by Bragaadeesh on Stack Overflow See other posts from Stack Overflow or by Bragaadeesh
Published on 2010-04-27T14:38:51Z Indexed on 2010/04/27 14:43 UTC
Read the original article Hit count: 331

Filed under:
|

Hi,

I am trying to do a conversion of a String to integer for which I get a NumberFormatException. The reason is pretty obvious. But I need a workaround here. Following is the sample code.

public class NumberFormatTest {
 public static void main(String[] args) {
  String num = "9.18E+09";
  try{
   long val = Long.valueOf(num);
  }catch(NumberFormatException ne){
   //Try to convert the value to 9180000000 here
  }
 }
}

I need the logic that goes in the comment section, a generic one would be nice. Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about numberformat