Help with negative numbers
I'm writing a calculator in Java and I am having trouble with negative numbers. The numbers are stored in and array of strings, called input, and Output is a text field where I display my results. Temp is a double. When I run the program and enter a negative number, it acts as if it is positive. I convert a string to a double, multiply by -1, and convert back to a string to display. What is wrong? Here is the relevant code:
{
temp = Double.parseDouble(input[2]);
temp = -1 * temp;
Output.setText(temp.toString());
}
P.S. Is there a special way to format code? If so, what is it?