I am not a total beginner at programming, but I am a total newbie with Java. I followed this tutorial
http://netbeans.org/kb/docs/java/gui-functionality.html#Exercise_1, and had no problem doing the exercise, but the results are confusing me.
The attached screenshot shows an error of .000002 when adding 12.6 and 9.3.
Some results compute perfectly though. 11.25 + 13.5 gives 24.75, but 111.3 + 50.9 gives 162.20001
The relevant code is:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// First we define float variables.
float num1, num2, result;
// We have to parse the text to a type float.
num1 = Float.parseFloat(jTextField1.getText());
num2 = Float.parseFloat(jTextField2.getText());
// Now we can perform the addition.
result = num1+num2;
// We will now pass the value of result to jTextField3.
// At the same time, we are going to
// change the value of result from a float to a string.
jTextField3.setText(String.valueOf(result));
}
I'm happy to post all my source code if required, though I have not deviated from the exercise except that my buttons 1 and 2 are swapped around, but I cannot see how that would matter.
I would be very appreciative of any assistance.