我正在构建一个计算器,我之前已经提出了问题,请参阅上一个链接:Building an interest rate calculator, however it won't produce figure
我想在输入时用逗号显示一些字段,我在这里找到了一些代码,它似乎与格式化有关,但现在计算只返回NaN。
为什么添加逗号的想法会阻止它工作?
以下是我用来添加逗号的代码,计算器的代码位于上一个链接:
HTML:
Shared class \"User\" has no method handling POST /594fcbeee223ce23620a3e12/accounts?access_token=Dg8qkXIHEck9fS0taCPWxklSVwD6HivN7iVU0lq0SBhaXQ8dMJmo6j8WxQGBNKRD
计算器JS:
user
Comma JS(在另一个文件中):
<div class="col-md-10 col-md-offset-1 form-body form-group">
<h2 class="form-heading">Find out how much your mortgage will cost</h2>
<div class="row text-muted">
<div class="col-md-5 col-md-offset-1 calc-input">
<h3>Purchase Price</h3>
<div class="input-group">
<span class="input-group-addon">£</span>
<input type="text" class="form-control comma" id="pp" placeholder="150,000" onchange="depositValue()">
</div>
<h3>Deposit</h3>
<div class="row text-muted">
<div class="col-md-4">
<div class="input-group">
<input type="text" class="form-control" id="percent" placeholder="10" onchange="depositValue()">
<span class="input-group-addon">%</span>
</div>
</div>
<div class="col-md-8">
<div class="input-group">
<span class="input-group-addon">£</span>
<input type="text" class="form-control comma" id="dp" placeholder="15,000" onchange="depositPercent()">
</div>
</div>
</div>
<h3>Mortgage Term</h3>
<div class="input-group">
<input type="text" class="form-control" id="mt" placeholder="25">
<span class="input-group-addon">Years</span>
</div>
<h3>Interest Rate</h3>
<div class="input-group">
<input type="text" class="form-control" id="ir" placeholder="4">
<span class="input-group-addon">%</span>
</div>
</div>
<div class="col-md-5 text-center">
<h3>Estimated Monthly Payment:</h3>
<p id="result"></p>
</div>
</div>
<div class="row text-muted">
<div class="col-md-10 col-md-offset-1 text-center">
<button class="btn btn-cta" onclick="calculate()">Calculate</button>
</div>
</div>
</div>
答案 0 :(得分:1)
当你添加逗号时,它不再是一个数字,而是一个字符串。当你进行计算时,你必须通过在处理之前将它们剥离来解释它。