-3

I am new to Java. creating calculator which calculates number from user input. I have 2 Jtextfield in my application where user input numbers. For example in first field user input 45678.230 and in second field 23214.210 which gives me subtraction result is 22464 but everything i want is full result followed by .(dot) so my answer should be 22464.02

String n1opn = n1open.getText();
String n1clsd = n1close.getText();
        
        
double n1intopen = (int) Double.parseDouble(n1opn);
double n1intclose = (int) Double.parseDouble(n1clsd);
double n1ltr = n1intclose - n1intopen;

System.out.println("output  "+ n1ltr);
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

1 Answers1

-1

You seem to be casting your inputs to an int. Integers don't have any decimal bits so using double is correct for your case!

Henry Twist
  • 5,666
  • 3
  • 19
  • 44