the actual value of cos(15) is 0.9659258262890682867497431997289. but when i entered Math.cos(15) int the Google Chrome console, it's showing -0.7596879128588205 as the result. Why would it show this error? Why can't JavaScript return 0.9659258262890682867497431997289?
Asked
Active
Viewed 2,292 times
1
-
and [Why is Math.Cos returning the wrong value?](http://stackoverflow.com/q/4168151/218196) – Felix Kling May 10 '14 at 08:50
2 Answers
12
Math.cos
takes its argument in radians. Thus, you first need to convert the 15 degrees to radians before calling Math.cos
var degrees = 15;
var radians = degrees * Math.PI / 180;
var cosOf15 = Math.cos(radians);

Mattias Buelens
- 19,609
- 4
- 45
- 51
5
-.759 is when the argument is in radians, .965 is when it's in degrees. All you have to do is convert to radians to get the result you want.

Meredith
- 844
- 6
- 17
-
-
This won't work. The result of `Math.cos` is not in radians, it's the *argument* that's in radians! – Mattias Buelens May 10 '14 at 08:49
-
-
Again, no. You need to convert degrees to radians, so you multiply by pi/180. I'd recommend you give your answer a quick test before posting it... – Mattias Buelens May 10 '14 at 08:52