首页 > 解决方案 > 将excel公式转换为javascript问题

问题描述

excel中的公式

=AVERAGE($B$20,$C$20)/((PI()/4)*(AF21+0.01)^2)

基本上是这样的:

=AVERAGE(5000,4500)/((PI()/4)*(0.3859+0.01)^2)

输出为 38586

javascript中的公式

function calcUltimate(max, min, radius) {
        return (((max + min) / 2) / (Math.pow(((Math.PI / 4) * (radius + 0.01)), 2))).toFixed(0);
    }

输出为 49130

我根本无法让输出匹配。我不知道我在这里做错了什么。

标签: javascriptexcel

解决方案


请试试这个:

function calcUltimate(max, min, radius) {
   return parseInt((((max + min) / 2) / ((Math.PI / 4) * Math.pow((radius + 0.01), 2))).toFixed(0));
}

推荐阅读