0

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?

Sotirios Delimanolis
  • 263,859
  • 56
  • 671
  • 702

2 Answers2

10

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
  • 18,790
  • 4
  • 43
  • 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
  • 834
  • 6
  • 16