I want to give the result the Math.cos() method in java in degrees.I have tried methods like converting from radians to degrees. But I discovered that any number I pass into the Math.cos() method is being treated as radians,irrespective of whether I convert.Please I can I make it give me the result in degrees.Thanks.
Asked
Active
Viewed 2.6k times
3 Answers
11
use Math.toRadians to convert your degrees to radians to pass to Math.cos for example
double blah = Math.cos(Math.toRadians(50));
I think that is what you are asking. There are quite a lot of similar questions here.

azp74
- 1,841
- 2
- 17
- 23
5
You can use Math.toDegrees()/Math.toRadians()
Converts an angle measured in radians to an approximately equivalent angle measured in degrees/radians.
Note that public static double cos(double a) expect the parameter in radians:
a - an angle, in radians.

Maroun
- 94,125
- 30
- 188
- 241
2
I discovered that any number I pass into the
Math.cos()
method is being treated as radians, irrespective of whether I convert.
The discovery is quite correct, and is precisely why you convert. Once you've done the conversion, you pass the resultant angle (which is in radians) to Math.cos()
, and everyone is happy.

NPE
- 486,780
- 108
- 951
- 1,012