VueJs中的数学计算未显示正确的结果

时间:2018-12-06 21:32:41

标签: javascript excel vue.js

我想执行一系列计算,但最后一次计算却没有给我想要的结果。

所以,下面是我的输入字段:

<div class="affordability-input">
    <input type="text" v-model="gross_income" placeholder="Enter gross monthly income (R)">
    <input type="text" v-model="loan_term" placeholder="Payment term (years)">
    <input type="text" v-model="interest_rate" placeholder="Interest Rate (%)">
    <button @click="calculate" class="bg-blue">Calculate</button>
</div>

我必须计算每月还款额,每月利息和总还款额,并且一切似乎都可以进行。 每月还款=先生 月利率=米尔 总还款= tr

this.n = parseFloat(this.loan_term) * 12;
this.mr = parseFloat(this.gross_income) * 0.3;
this.mir = parseFloat(this.interest_rate) / 12;
this.tr = parseFloat(this.n) * parseFloat(this.mr);

然后,我必须计算一个人的负担能力,公式如下图所示:

enter image description here

关于公式,P与this.mr相同,r为this.mir,n为this.n。

我这样写公式:

this.aff = this.mr * ((1 - Math.pow(( 1 + parseFloat(this.mir)), - parseFloat(this.n))) / parseFloat(this.mir));

整个方法如下:

calculate(){
        this.n = parseFloat(this.loan_term) * 12;

        this.mr = parseFloat(this.gross_income) * 0.3;

        this.mir = parseFloat(this.interest_rate) / 12;

        this.tr = parseFloat(this.n) * parseFloat(this.mr);

        this.aff = this.mr * ((1 - Math.pow(( 1 + parseFloat(this.mir)), - parseFloat(this.n))) / parseFloat(this.mir));

        this.show = true;               
        this.take = false;              

}

将公式放入计算器后,我得到的结果与excel工作表显示的结果相同,但是在网页上得到的结果却不同。

我的负担能力计算器有什么问题吗?上图的公式。如何在Javascript / vuejs中编写该公式

编辑:

我创建了一个片段

总收入= 60000 贷款期限= 20 利率= 10

除了负担能力外,所有答案似乎都是正确的。

我为此here创建了一个片段

1 个答案:

答案 0 :(得分:1)

您的利率需要除以100,以说明它是一个百分比值。 10%表示0.1。

相关问题