1

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
  • 274,122
  • 60
  • 696
  • 724

2 Answers2

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