java.lang.NumberFormatException: For input string: “20,475.00”

后端 未结 4 890
北荒
北荒 2021-01-13 19:58

i am trying to get the running balance of my system. To do it, i get the sum of all numbers in the jtable from column AMOUNT and subtract the sum to the value inside the txt

4条回答
  •  萌比男神i
    2021-01-13 20:51

    Use NumberFormat class instead of Float.parseFloat. It will allow you to specify a format for parsing a formatted number such as 20,475.00.

    Example:

    NumberFormat nf = NumberFormat.getInstance();
    // provided your Locale information matches your number format
    sum += nf.parse(tableLedger.getModel().getValueAt(i, 2).toString());
    

提交回复
热议问题