Excel 电子表格公式到 JavaScript 问题 #2
大家又来嗨了。我在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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)
makesx
an integer.You could try
Math.round(((x-0)*100)*100)/100
which makes thex = 8.609720...
intox=861
and then divides it to get thex=8.61
you're looking for, which is what they would suggest here....Also, not really sure why you're subtracting 0 from x...?
好吧,所以我又看了一遍,我想我第一次看的不够深入。
如果我理解的话,逻辑是这样的:
如果这是正确的,你可以在 excel 中使用
=MIN(1,$B28/IF($B$7=TRUE,$B$10,$B$5)) 来完成
(相同的引用),这意味着以下内容应该执行您想要的操作: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 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: