Hi guys

Im writing a small calculator application like the standard windows calculator using Java. Java isnt the ideal language for this project buts it for my course so i dont have a choice.

The problem I am having is with degrees and converting them.

My calculator has two radio buttons that flag the given angle as either radians or degrees.

the calculator has buttons to work out the tan, cos, sin of the given angle.

by without changing the number at all opertions like

Radians, 1 COS equate to 0.54 (which is correct)

...but the degree operations give the wrong answer. Leading me to assume that by default the program works in radians.

so I have tried to convert the angle to degrees both using the formula:

angle * 180 / PI and the Math.toDegrees(double) method. both give the same answer but if i then pass the new value to the tan, cos and sin functions the resulting answer is incorrect.

eg: Degrees 45 Tan gives -1.36 when it should give 1.

anyone have any ideas where Im going wrong???

cheers,

Ben.

a bit of the code. the other buttons are the same as the tan button event.

Code:

if((actionCmd.equals("Tan"))||(actionCmd.equals("Cos"))||
(actionCmd.equals("Sin"))||(actionCmd.equals("aTan"))||
(actionCmd.equals("aCos"))||(actionCmd.equals("aTan"))){
angleNum = Double.parseDouble(txtDisplay.getText());
if(angleUnits==1){ //if angle units = radians
//do nothing and radians works.
}else{ //if angle units = degrees
System.out.println(angleNum+"");
System.out.println("Calculated "+ (angleNum * 180 / Math.PI));
System.out.println("Math function "+Math.toDegrees(angleNum));
angleNum = Math.toDegrees(angleNum);
System.out.println(angleNum+"");
}//end of if ~ else block
}//end of if button is any of the angle buttons
if(actionCmd.equalsIgnoreCase("tan")){
double output = Math.tan(angleNum);
txtDisplay.setText(output+"");
return;
}