简体   繁体   English

转换Excel公式并使用等效的Javascript检索特定值

[英]Convert Excel formula and retrieve specific value with equivalent Javascript

I am trying to convert the below Excel formula to Javascript. 我正在尝试将以下Excel公式转换为Javascript。 I have tried several times and will show you the values that the formula spits out as well as the names for the cell references as needed. 我已经尝试了几次,将根据需要显示该公式吐出的值以及单元格引用的名称。 I will also show what I have tried and failed and even using an online Converter tool found here: 我还将展示我尝试过的和失败的,甚至使用这里找到的在线Converter工具进行的尝试:

http://excelformulabeautifier.com/ http://excelformulabeautifier.com/

Here is the formula: 这是公式:

=IF(B11<=B19,(B11*(B18/100) (B24/100)),IF(B11<=B21,(B19 (B18/100))+((B11-B19) (B20/100)),(B19 (B18/100))+((B21-B19) (B20/100))+((B11-B21) (B22/100)))*(B24/100)) = IF(B11 <= B19,(B11 *(B18 / 100) (B24 / 100)),IF(B11 <= B21,(B19 (B18 / 100))+((B11-B19) (B20 / 100)) ),(B19 (B18 / 100))+((B21-B19) (B20 / 100))+((B11-B21) (B22 / 100))*(B24 / 100))

Here is what the converter gave me: 这是转换器给我的:

(B11<=B19,(B11*(B18/100) (B24/100)),IF(B11<=B21,(B19 (B18/100))+((B11-B19) (B20/100)),(B19 (B18/100))+((B21-B19) (B20/100))+((B11-B21) (B22/100)))*(B24/100)) (B11 <= B19,(B11 *(B18 / 100) (B24 / 100)),IF(B11 <= B21,(B19 (B18 / 100))+((B11-B19) (B20 / 100)), (B19 (B18 / 100))+((B21-B19) (B20 / 100))+((B11-B21) (B22 / 100))*(B24 / 100))

But I am having trouble trying to figure out how to handle the nested if statements. 但是我很难弄清楚如何处理嵌套的if语句。 I am also not an Excel guru on trying to figure out whether the if statements are nested else statements as well. 我也不是试图弄清楚if语句是否嵌套else语句的Excel专家。

Any guidance would be greatly appreciated. 任何指导将不胜感激。 Here are the values for the different cells and what the input in them is as well as what the output needs to be: 以下是不同单元格的值以及它们中的输入以及输出需要是什么:

B11 - Sale Price - 90,000 B19 - Commission Amount First Break - 100,000 B18 - Commission Percent of sale price first amount - 6 B24 - Listing Broker Percent - 50 B21 - Commission Amount Second Break - 200,000 B20 - Commission Percent of sale price 2nd amount - 4 B22 - Commission Percent of sale price 3rd amount - 2 B11-售价-90,000 B19-首笔佣金金额-100,000 B18-佣金首笔交易金额的百分比-6 B24-上市经纪人百分比-50 B21-第二次佣金金额-200,000 B20-佣金第二笔交易金额的百分比- 4 B22-销售价格第三笔佣金的百分比-2

The output is for listing broker commission and the value is: 2700 输出是用于列出经纪人佣金的,其值为:2700

Any help is appreciated. 任何帮助表示赞赏。 Thanks! 谢谢!

var B11 = 90000;
var B19 = 100000; // - Commission Amount First Break -
var B18 = 6; // - Commission Percent of sale price first amount -
var B24 = 50; // - Listing Broker Percent 
var B21 = 200000; // - Commission Amount Second Break -
var B20 = 4;  // Commission Percent of sale price 2nd amount 
var B22 = 2; // - Commission Percent of sale price 3rd amount - 

var result;
if (B11 <= B19)
{
    result = (B11 * (B18/100) * (B24/100));
}
else if(B11 <= B21)
{
    result = (B19*(B18/100))+((B11-B19)*(B20/100));
}
else
{
    result = (B19*(B18/100))+((B21-B19)*(B20/100))+((B11-B21)*(B22/100))*(B24/100);
}

console.log(result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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