简体   繁体   English

将此 Excel 公式转换为 Javascript

[英]Converting this Excel formula to Javascript

My Javascript knowledge is very limited and I was wondering if someone could give me a hand converting this Excel formula into Javascript.我的 Javascript 知识非常有限,我想知道是否有人可以帮我将这个 Excel 公式转换为 Javascript。

Please see the formula below请看下面的公式

=ROUNDDOWN(
    IF(
        I7 = 10000,
        88.4% * (I7/107*7),
        IF(
            I7 = 20000,
            89.4 * (I7/107*7),
            IF(
                I7 = 40000,
                90.40 * (I7/107*7),
            )
        )
    ),
    0
)

I7 is the input I7 是输入

Basically, anything between 10000 and 19999 uses 88.4% * (I7/107*7)基本上,10000 到 19999 之间的任何东西都使用 88.4% * (I7/107*7)

20000 and 39999 uses 89.4 * (I7/107*7) 20000 和 39999 使用 89.4 * (I7/107*7)

40000 and above use 90.40 * (I7/107*7) 40000及以上使用90.40*(I7/107*7)

Round down to the nearest whole number and output向下舍入到最接近的整数和 output

Thanks in advance!提前致谢!

This is what you asked, not what the formula did这是你问的,不是公式做了什么

 const calculate = num => { if (num < 10000) return "N/A"; num = num / 107 * 7; let pct = 1/100; if (num < 20000) pct *= 88.4; else if (num < 30000) pct *= 89.4; else if (num >= 40000) pct *= 90.40; return Math.round(num * pct) } console.log( calculate(10), calculate(10000), calculate(15000), calculate(25000), calculate(50000) )

I write here a basic code so you can follow.我在这里写了一个基本代码,以便您可以遵循。

function calCell(input) {
  var value;
  switch(true)
  {
    case input >= 10000 && input < 20000 :
      value = Math.floor(88.4 / 100 * (input / 107 * 7));
    break;
    case input >= 20000 && input < 40000 :
          value = Math.floor(89.4 / 100 * (input / 107 * 7));
    break;
    case input >= 40000 :
      value = Math.floor(90.4 / 100 * (input / 107 * 7));
    break;
    default:
    //I don't know what to do if your value < 10000, but you can put it here
    break;
  }
  return value;
}

console.log(calCell(12345));

Most short and simplified!最简短最简单的!

function RoundDown(num){
if (num >= 10000 && num <20000) {num=num*88.4/100*107*7}
if (num >= 20000 && num <40000) {num=num*89.4/100*107*7}
if (num >= 40000) {num=num*90.4/100*107*7}
return Math.floor(num)
}

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

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