PDA

View Full Version : Javascript math problem


stathis30_2000
08-13-2008, 10:11 PM
Hi all,

I am facing a very strange problem concerning javascript math functions ..
I need to calculate the cos,sin values of some angles .When I try Math.cos(0) I get result =1 which is correct. When I try Math.cos(180) I get result=-0.59 ! As fas as I remember cos(180) = -1 ... Why is that happening??

Please help me, is urgent.

Thanks
ST

codefux
08-13-2008, 10:51 PM
Hi,

I think you have to call the cos-Method with the radian instead of the angle.

result = Math.cos(yourAngleVal * Math.PI/180)
.. should work!

stathis30_2000
08-13-2008, 10:55 PM
I was just about to reply writing the same thing :)

Thank you very much for your reply though!