javascript - 将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
我根本无法让输出匹配。我不知道我在这里做错了什么。
解决方案
请试试这个:
function calcUltimate(max, min, radius) {
return parseInt((((max + min) / 2) / ((Math.PI / 4) * Math.pow((radius + 0.01), 2))).toFixed(0));
}
推荐阅读
- r - R仅当数据框中存在一组值时才选择行
- javascript - 关于缩放的 D3 图形问题
- c++11 - 了解实际来电者的有效方法
- java - 使用 Java 的 getResource 找不到文件
- addeventlistener - 使用 slotRenderEndedEvent 刷新插槽,但未售出时不会触发
- php - 将属性从刀片传递到路由到控制器
- java - 使用 javafx webview 登录 Microsoft OpenId
- wso2is - 将 WSO2 IS 连接到 SQL Server
- c# - 如何在 C# 中通过 SMO 中的 GO 拆分 SQL 脚本
- android - 尝试在空对象引用上调用虚拟方法“android.os.IBinder android.view.SurfaceControl.getHandle()”