Excel 电子表格公式到 JavaScript 问题 #2

发布于 2024-09-08 13:44:37 字数 941 浏览 8 评论 0原文

大家又来嗨了。我在尝试在 Excel 电子表格到 JavaScript 转换中正确匹配时再次遇到一些问题。

这是 Excel 公式:

 =IF(IF($B$7=TRUE,$B$28/$B$10,$B$28/$B$5)>1,1,IF($B$7=TRUE,$B$28/$B$10,$B$28/$B$5))

 WHERE
 B7  = TRUE
 B28 = 76800
 B10 = 892015
 B5  = 999500

这是我迄今为止拥有的 JavaScript:

 function percent(x) { return Math.round((x-0)*100) + '%'; }

 if($('#section179').is(':checked'))
 {
  var percentRepaid = $("#rev3DScanYear").val() / $("#section179Real").val();

  if (percentRepaid > 1)
  {   
    $("#paymentCashPer").val('100.00');
  }else
  {
    percentRepaid = $("#rev3DScanYear").val() / $("#SalePrice").val();
    $("#paymentCashPer").val(percent(percentRepaid));
  }
}else
{
 //to be done   
}

 WHERE
 rev3DScanYear  = 76800
 SalePrice      = 999500
 section179Real = 892015

对于 JavaScript 代码,我不断获得 8% 的值,并且我应该获得 8.61% 的值 b> 就像电子表格上一样。

一如既往,任何帮助都会很棒! :o)

大卫

Hey again everyone. Yet again i am having some problems with trying to get the match correct on this Excel Spreadsheet to JavaScript conversion.

Here is the excel formula:

 =IF(IF($B$7=TRUE,$B$28/$B$10,$B$28/$B$5)>1,1,IF($B$7=TRUE,$B$28/$B$10,$B$28/$B$5))

 WHERE
 B7  = TRUE
 B28 = 76800
 B10 = 892015
 B5  = 999500

And this is my JavaScript i have so far:

 function percent(x) { return Math.round((x-0)*100) + '%'; }

 if($('#section179').is(':checked'))
 {
  var percentRepaid = $("#rev3DScanYear").val() / $("#section179Real").val();

  if (percentRepaid > 1)
  {   
    $("#paymentCashPer").val('100.00');
  }else
  {
    percentRepaid = $("#rev3DScanYear").val() / $("#SalePrice").val();
    $("#paymentCashPer").val(percent(percentRepaid));
  }
}else
{
 //to be done   
}

 WHERE
 rev3DScanYear  = 76800
 SalePrice      = 999500
 section179Real = 892015

For the JavaScript code i keep getting a value of8% and i should be getting a value of8.61% as it has on the spreadsheet.

As always, any help would be great! :o)

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铁轨上的流浪者 2024-09-15 13:44:37

Math.round((x-0)*100) 使 x 成为整数。

您可以尝试使用 Math.round(((x-0)*100)*100)/100 ,这使得 x = 8.609720... 变为 x= 861,然后除以得到您要查找的 x=8.61,这就是他们的建议 此处

...另外,不太确定为什么要从 x 中减去 0...?

Math.round((x-0)*100) makes x an integer.

You could try Math.round(((x-0)*100)*100)/100 which makes the x = 8.609720... into x=861 and then divides it to get the x=8.61 you're looking for, which is what they would suggest here.

...Also, not really sure why you're subtracting 0 from x...?

分開簡單 2024-09-15 13:44:37

好吧,所以我又看了一遍,我想我第一次看的不够深入。

如果我理解的话,逻辑是这样的:

If Section179 is checked then Divisor is Section179Real, else it is SalePrice.

Give me the smaller of 1.00 or (rev3DScanYear / Divisor).

如果这是正确的,你可以在 excel 中使用 =MIN(1,$B28/IF($B$7=TRUE,$B$10,$B$5)) 来完成 (相同的引用),这意味着以下内容应该执行您想要的操作:

var Divisor = $("#SalePrice");

if($('#section179').is(':checked'))
{
  Divisor = $("#section179Real");
}

$("#paymentCashPer").val(Math.round(100*(Math.min(1, $("#rev3DScanYear")/Divisor)*100)/100;

Ok, so I've been looking at this again, and I think I didn't look deeply enough the first time.

The logic, if I understand it, is this:

If Section179 is checked then Divisor is Section179Real, else it is SalePrice.

Give me the smaller of 1.00 or (rev3DScanYear / Divisor).

If that's correct, you can do it in excel with =MIN(1,$B28/IF($B$7=TRUE,$B$10,$B$5)) (same references), which means that the following should do what you want it to:

var Divisor = $("#SalePrice");

if($('#section179').is(':checked'))
{
  Divisor = $("#section179Real");
}

$("#paymentCashPer").val(Math.round(100*(Math.min(1, $("#rev3DScanYear")/Divisor)*100)/100;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文