Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  84] [ 3]  / answers: 1 / hits: 16230  / 10 Years ago, sun, march 30, 2014, 12:00:00

When I use Math.sin(90) for calculating Sine of 90 degrees in javascript it returns 0.8939966636005565, but sin(90) is 1. Is there a way to fix that? I need accurate values for any angle.



<!DOCTYPE html>
<html>
<body>
<p id=demo>Click the button calculate value of 90 degrees.</p>
<button onclick=myFunction()>Try it</button>
<script>
function myFunction(){
document.getElementById(demo).innerHTML=Math.sin(90);
}
</script>




More From » math

 Answers
49

Math.sin expects the input to be in radian, but you are expecting the result of 90 degree. Convert it to radian, like this



console.log(Math.sin(90 * Math.PI / 180.0));
# 1


As per the wikipedia's Radian to Degree conversion formula,



Angle in Radian = Angle in Degree * Math.PI / 180

[#71705] Friday, March 28, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irvinjovannix

Total Points: 416
Total Questions: 94
Total Answers: 117

Location: South Korea
Member since Sun, Aug 8, 2021
3 Years ago
;