this is the code in my "add" button for my calculator. Im having problem in some data type validations: Example: 9.2+3.2 = 12.4, in this way my calculator works fine. but if you entered integer first like this: 9 + 3.2, the result will only be 3.2. How do you think can i parse the first value if the decimal exists on the second value?
private void btn_AddActionPerformed(java.awt.event.ActionEvent evt) {
//FOR DOUBLE CALCULATION
if(ta_DisplayField.getText().contains(".") || c_History.contains(".")){
c_Operator = '+';
c_Container = "+";
c_History = c_History + "+";
ta_History.setText(c_History);
c_totalDouble = (double)c_totalInt + Double.parseDouble(ta_DisplayField.getText());
ta_DisplayField.setText(c_totalDouble + "");
}
}
//FOR INTEGER CALCULATION
else{
c_Operator = '+';
c_Container = "+";
c_History = c_History + "+";
ta_History.setText(c_History);
c_totalInt = c_totalInt + Integer.parseInt(ta_DisplayField.getText());
ta_DisplayField.setText(c_totalInt + "");
}
}
}