Search code examples
javascriptmathdegreesradians

Math.sin incorrect results even when converted to degrees


I'm trying to use sin on a variable and I saw you can convert it by using / (Math.PI / 180) but that seems contradictory if you want to convert it to degrees.. How do I properly convert and use sin in degree form? (On an iPhone calculator, for example it returns ~.707 from an input of 45, while this returns ~.806).

function click25() {
    if (vi === 0) {
        reactant = Math.sin(reactant / (Math.PI / 180))
    }
}

Solution

  • You need to multiply the value in degree by (pi/180) to convert into the equivalent value in radians

    var reactant = 45;
    var vi = 0;
    function click25() {
        if (vi === 0) {
            reactant = Math.sin(reactant * (Math.PI / 180))
        }
        console.log(reactant);
    }
    
    click25();