public class SimpleTrig {
public static void main(String[] args) {
DecimalFormat dx;
dx = new DecimalFormat("0.000");
String angleStr;
double angle, angleCosine;
angleStr = JOptionPane.showInputDialog(null,"Enter an angle (in degrees)");
angle = Double.parseDouble(angleStr);
angleCosine = Math.cos(Math.toRadians(angle));
JOptionPane.showMessageDialog(null, "The cosine of " + angle
+ " degrees is " + dx.format(angleCosine));
}
}
The output of angleCosine is giving me an output of 0.000 as my final answer regardless of any angle I input.
Use
new DecimalFormat("#.###")