我在尝试检索计算值并将其传递给 JformattedTextfield 时遇到了这个问题,我知道由于 jformattedTextfield ( , ) ,Float 不能接受 1,500.00 。有没有办法绕过这个问题?
private void SellButtonActionPerformed(java.awt.event.ActionEvent evt) {
float foreign , sellingRate, localAmount;
try{
DefaultTableModel dtm=(DefaultTableModel)p1.getModel();
int i = p1.getSelectedRow();
String s1=dtm.getValueAt(i,2).toString();
txt_rate.setText(s1);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Select Currency First");
}
foreign = Float.parseFloat(txt_select.getText());
sellingRate = Float.parseFloat(txt_rate.getText());
localAmount = foreign / sellingRate;
txt_amount.setValue(localAmount);
}
错误信息
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "1,500.00"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1241)
at java.lang.Float.parseFloat(Float.java:452)
我可以计算出 { 1,000 }以下的数字
预期结果