Home > Blockchain >  FATAL EXCEPTION: main For input string: "5862.270"
FATAL EXCEPTION: main For input string: "5862.270"

Time:05-05

I am trying to format a decimal number as a currency and I have tried probably all methods but for some reason I keep getting FATAL EXCEPTION: mainjava.lang.NumberFormatException: For input string: "5862.270" any solutions?

Integer num = Integer.parseInt(parkingList.get(parkingList.size() - 2).getTotalValue());
DecimalFormat svSE = new DecimalFormat("#,###.000");
String result = svSE.format(num);
//format.setMinimumFractionDigits(0);

viewHolder.totalbyday.setText(result);

My code is inside an adapter as well if that changes anything!

I also tried removing Integer.parseInt(parkingList.get(parkingList.size() - 2).getTotalValue()); and just putting the number 5862.270 and Istill get the same exception

CodePudding user response:

It's because you are trying to parse a decimal point number into an Integer.

Change:

Integer num = Integer.parseInt(parkingList.get(parkingList.size() - 2).getTotalValue());

to:

Double num = Double.parseDouble(parkingList.get(parkingList.size() - 2).getTotalValue());
// or
Float num = Float.parseFloat(parkingList.get(parkingList.size() - 2).getTotalValue());
  • Related