-2

I am trying to convert String temp = 129.70 to number.

I tried:

String decimalNumber= "-129.70";
System.out.println(Integer.parseInt(decimalNumber));

But it is giving me exception Exception in thread "main" java.lang.NumberFormatException: For input string: "-129.70"

0

2 Answers 2

1

129.70 is not an integer. It's a double. Change class and you should be fine.

System.out.println(Double.parseDouble(decimalNumber))
1
  • Tried and it worked, I am surprised it was not available on any threads on google.
    – paul
    Jun 23, 2018 at 14:58
-4

Try this:

    String decimalNumber= "-129.70";
    System.out.println(Integer.parseDouble(decimalNumber));
1
  • 1
    All you would get by trying this is a compiler error, because Integer.parseDouble does not exist (unless this is some Integer class other than java.lang.Integer). Jun 23, 2018 at 15:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.