I have this problem where I am trying to retrieve and pass calculated values to JformattedTextfield, I know 1,500.00 can not be accepted by Float due to the jformattedTextfield (,). Is there a way to bypass this issue ?
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);
}
Error Message
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)
I can calulate numbers under {1,000}
Expected result