简体   繁体   中英

Convert complex excel formula to javascript

To start I'm not that well versed in javascript and I'm trying to convert this complex excel formula to javascript without any luck.

=DEGREES(ASIN(SIN(RADIANS(59.036))*SIN(RADIANS(150))))/2

Here's what I have so far

var x = DEGREES(Math.asin(Math.sin(RADIANS(59.036))*Math.sin(RADIANS(150))))/2

Obviously, DEGREES and RADIANS are wrong and I can't figure what the javascript equivalent would be.

(BTW the correct answer is 5.831)

Well, you could write your own DEGREES and RADIANS functions, which only involve a little math:

function degrees(x) { return x * 180 / Math.PI; }
function radians(x) { return x * Math.PI / 180; }

var x = degrees(Math.asin(Math.sin(radians(59.036))*Math.sin(radians(150))))/2;

Define both functions yourself. They are both trivial to implement.

function DEGREES(radians){
  return (radians * 180 / Math.PI);
}
function RADIANS(degrees){
  return (degrees / 180 * Math.PI);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM