Excel电子表格公式到javascript问题

时间:2010-07-06 19:52:27

标签: javascript excel excel-2007 excel-formula

嘿所有我想弄清楚如何计算从Excel 2007 fx到javascript的这个公式:

 =(B12*'ROI endo only'!B5)/(1-(1+Data!B12)^(-Data!B13))

 WHERE
   B12 = 0.49%
   B5  = 99,500
   B13 = 48

到目前为止,我将此作为我的javascript代码:

 var theCalc = (0.49 * 99500) / (1 - (1 + 0.49)^(-48));

 alert(theCalc);

虽然,我没有得到正确的结果,就像我在电子表格上得到的那样。电子表格的值 2,332 ,我从javascript代码获得 -1015.72916 ...

任何帮助都可以解决我的问题:o)

更新

 var theCalc = (0.0049 * 99500) / (1 - Math.pow((1 + 0.0049), -48));

大卫

2 个答案:

答案 0 :(得分:0)

我认为问题出在^上。在javascript中,^并不意味着像在VB中那样指数。您必须使用Math.pow方法。试试这个JavaScript:

var theCalc = (0.49 * 99500) / Math.pow( 1 - (1 + 0.49), -48 );

答案 1 :(得分:0)

<html>
<head>
<title>test</title>
</head>

<body onload="testfun();">

<script type="text/javascript"> 
function testfun(){
    document.getElementById('testRes').innerHTML = (.0049 * 99500) / (1 - Math.pow((1+.0049), -48));
}
</script>

The answer:
<div id="testRes"></div>

结果为2331.290084493742

相关问题