0

I write a program like this:

double degrees = 45.0;
double radians = Math.toRadians(degrees);
System.out.println(Math.tan(radians));

When I run this code I get the result is 0.9999999999999 Is there a way to calculate the correct tan function in java? Can you help me. Thank you!

2
  • Using doubles will always create rounding issues. If you don't care too much about precision you can simply round the result to n decimals.
    – assylias
    Commented Jan 28, 2015 at 14:12
  • why don't you round it?
    – SMA
    Commented Jan 28, 2015 at 14:14

0

Browse other questions tagged or ask your own question.