jQuery 利息计算器 - 计算每月付款的信用金额
我写了一个小型 jQuery 利息计算器。
- 它正在计算每月还款的信用金额
问题是我的利息计算逻辑完全错误。
看看:
//Get the value - monhtly repayment
var InputedValue = $('form input[name="val1"]').val();
// 12 ,18, 24, 30, 36 - NumberOfMonths
for (var i = 12; i <= 36; i += 12) {
// j = 20 - Deposit in %
for (var j = 10; j <= 10; j += 10) {
// g = 20, 30 - InterestPerYear in %
for (var g = 10; g <= 10; g += 10) {
var InScaleOfYear = i / 12;
// Amount of payment excluding deposit
var AmountOfPayments = (InputedValue * (i - 1)); // rat bedzie o jedna mniej niz ilosc miesiecy, bo wplata poczatkowa
// Amount of payment including deposit
var AmountInTotal = (AmountOfPayments * 100) / (100 - j);
// Deposit
var Deposit = AmountInTotal - AmountOfPayments;
// Amount of payment in one year
var AmountOfPaymentInOneYear = (AmountOfPayments / InScaleOfYear);
var InterestPerYear = ((AmountOfPaymentInOneYear * g) / 100);
// Interest in total
var InterestInTotal = InterestPerYear * InScaleOfYear;
// Amount of credit
var AmountOfCredit = (AmountOfPayments + Deposit) - InterestInTotal;
$('table tbody').append('<tr><td>'
+ i + '</td><td>'
+ "at " + j + "% = " + Deposit.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestPerYear.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestInTotal.toFixed(2) + '</td><td>'
+ AmountOfPayments.toFixed(2) + '</td><td>'
+ AmountInTotal.toFixed(2) + '</td><td>'
+ AmountOfCredit.toFixed(2) + '</td></tr>');
}
}
}
你们有人在做类似的事情吗?如何计算具有以下信息的利息:
- 月数/年数 (
i = Months
) - 每月付款金额 (
$('form input[name="val1"]').val ();
) - 存款金额 (
j = 存款
) - 利率 (
g = 利率
)
如您所见,循环为到位几个月/存款/利息。只是需要一些有关循环中计算利息的登录帮助。
I wrote small jQuery interest calulcator.
- it is calculating amount of credit from monthly re-payment
The problem is that my interest calculation logic is just purely wrong.
Have a look:
//Get the value - monhtly repayment
var InputedValue = $('form input[name="val1"]').val();
// 12 ,18, 24, 30, 36 - NumberOfMonths
for (var i = 12; i <= 36; i += 12) {
// j = 20 - Deposit in %
for (var j = 10; j <= 10; j += 10) {
// g = 20, 30 - InterestPerYear in %
for (var g = 10; g <= 10; g += 10) {
var InScaleOfYear = i / 12;
// Amount of payment excluding deposit
var AmountOfPayments = (InputedValue * (i - 1)); // rat bedzie o jedna mniej niz ilosc miesiecy, bo wplata poczatkowa
// Amount of payment including deposit
var AmountInTotal = (AmountOfPayments * 100) / (100 - j);
// Deposit
var Deposit = AmountInTotal - AmountOfPayments;
// Amount of payment in one year
var AmountOfPaymentInOneYear = (AmountOfPayments / InScaleOfYear);
var InterestPerYear = ((AmountOfPaymentInOneYear * g) / 100);
// Interest in total
var InterestInTotal = InterestPerYear * InScaleOfYear;
// Amount of credit
var AmountOfCredit = (AmountOfPayments + Deposit) - InterestInTotal;
$('table tbody').append('<tr><td>'
+ i + '</td><td>'
+ "at " + j + "% = " + Deposit.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestPerYear.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestInTotal.toFixed(2) + '</td><td>'
+ AmountOfPayments.toFixed(2) + '</td><td>'
+ AmountInTotal.toFixed(2) + '</td><td>'
+ AmountOfCredit.toFixed(2) + '</td></tr>');
}
}
}
Any of you working on something similar? How can I calculate interest having following information:
- number of month / years (
i = months
) - amount of monthly payment (
$('form input[name="val1"]').val();
) - amount of the deposit (
j = deposit
) - interest rate (
g = interest rate
)
As you can see, the loop is in place for months/deposit/interest. Just need some help with the login of calculating interest in the loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你的措辞有点混乱。但我的理解是,你想根据每月还款额和一定的利率来计算出某人可以承受多少信贷。正如其他人指出的那样,您首先需要在纸上进行此操作,以确保您拥有适用于利息类型和复利期限的正确公式。但这不是 StackOverflow 的目的,我们在这里专注于编程!因此,我们假设信用卡式贷款具有复利和每月付款(您可以根据需要重写任何其他公式)。
我可以在网上找到这些公式的最佳资源在这里:贷款或投资公式。此页面已预先解决了几乎所有变量的复合公式!所以你不需要记住大学里的商业数学入门课。好的。
所以现在我们只需要将正确的公式翻译成 JavaScript 即可。这就是我们的 StackOverflow 观众希望看到的!在我们的例子中,其中:
A = (P/i)[1-(1+i)^-N]
我们希望它能够使它们倍增。所以让我们添加星号。 A = (P/i) * (1 - (1+i)^-N)
Math.pow() 代替。 A = (P/i) * (1 - Math.pow((1+i),(-N))
完成!这可以在 JavaScript 中工作。一个具有舒适变量名称的人类可读示例怎么样?< /p>
就这样吧!这将根据每月付款、给定的 APR 利率以及 12、24 和 12 日、24 日和 24 日计算可用信用总额。 36 个月期限。如果这不完全是您想要的目标,请阅读数学教程并选择另一个公式来转换为 JavaScript!
Your wording is a little confusing. But my understanding is that you want to figure out how much credit someone can afford based on a monthly payment and some interest rate. As others have pointed out, you first need to do this on paper to make sure you have the correct formula for the type of interest and compounding period. But that's not what StackOverflow is about, we're here to focus on programming! So let's assume credit card style lending with compound interest and monthly payments (you can rewrite for any other formula as needed).
The best resource I could find online for these formulas is here: Loan or Investment Formulas. This page has the compound formula pre-solved for almost any variable! So you don't need to remember that intro to business math class from college. Nice.
So now we just need to translate the correct formula into JavaScript. This is what our StackOverflow audience wants to see! In our case, where:
A = (P/i)[1-(1+i)^-N]
we want it to multiply them. So lets add the asterisk. A = (P/i) * (1 - (1+i)^-N)
Math.pow() instead. A = (P/i) * (1 - Math.pow((1+i),(-N))
Done! This can work in JavaScript. How about a nice human readable sample with comfortable variable names?
There you go! That'll calculate the total available credit based on some monthly payment, a given APR interest rate and 12, 24 & 36 month terms. If this wasn't exactly the goal you had in mind, go read that math tutorial and select another formula to translate to JavaScript!
主要问题是您正在尝试使用非微积分方法来解决微积分问题。如果您不知道的话,微积分是数学的一个分支,本质上是试图解决 X/0 问题。就复利而言,贪婪的银行试图从利息中榨取尽可能多的钱。
一开始是按月收取利息,但他们意识到,如果每天收取利息,他们可以获得更多。比如说,每月10%的利息,分为天,每天1/3%。这是因为前一天的利息是下一个利息周期计算(或复利)的一部分。如果每小时、每分钟、每秒进行划分,他们可以获得更多,直到基本上变成“即时利息”。于是,复利就诞生了。
(由于流行和混乱,政府强制使用 APR 术语将复利百分比转换为我们普通人可以理解的“年利率”。所以,如果它说 APR,而且大多数人都这样做,那就是复利。)
复利是一个 X/0 问题,因为您试图获得即时利息。 维基百科关于复利的文章应该提供一些计算复利的有用公式。然而,在使用此类公式时要记住的一件重要事情是,您不能仅采用 APR 之类的值除以 12 来获得 MPR 数字。不然就不是复利了,也没有那么简单。
The main issue is that you're trying to solve a calculus problem by using non-calculus methods. Calculus, if you aren't aware, is a branch of mathematics for essentially trying to solve for X/0 problems. In the case of compound interest, it's a case of greedy banks trying to squeeze as much money as possible from the interest.
This started out as monthly interest, but they realized that if they charged per day, they could get more. It's the same interest of say, 10% per month, divided into days as 1/3% per day. That's because the interest from the previous day is part of the calculation (or compounded) for next interest cycle. They could get more if they divided per hour, per minute, per second, until it became basically "instant interest". Thus, compound interest is born.
(Because of the popularity and confusion, the govt mandated the use of the APR term to translate the compound interest percentage into an "Annual Percentage Rate" that us normal people can relate to. So, if it says APR, and most do, it's compound interest.)
Compound interest is a X/0 problem, because you trying to get instant interest. Wikipedia's article on compound interest should provide some useful formulas for calculating compound interest. However, one important thing to remember when using formulas like these is that you can't just take something like APR and divide by 12 to get a MPR figure. Otherwise, it wouldn't be compound interest, and it's not that simple.
试试下面的这个页面,它还包含 Excel 电子表格,这很有帮助。
http://www.yorku.ca/amarshal/mortgage.htm
如果您可以关注脑子里有excel计算,你就可以轻松地敲出代码。
Try this page below, it also contains excel spreadsheet which helps greatly.
http://www.yorku.ca/amarshal/mortgage.htm
If you can follow the excel calculations in your head, you can slap out the code easily.
这实际上取决于您正在寻找的兴趣类型(复合/简单/等)。例如,我会在这里查看:
http://www.hotscripts.com/search/javascript/interest
It really depends on the type of interest you're looking for (compound/simple/etc). For examples I'd look here:
http://www.hotscripts.com/search/javascript/interest
使用公式
A=P(1+r/n)^nt
其中,
A:未来价值加利息
P:本金金额
r :年利息(小数)
否。每年复利的次数
t:没有。资金投资年数
在接受用户的 int 值后,将“r”值除以 100,将其转换为浮点值。提供单选按钮来选择投资类型,如季度、月度、年度等,相应地您可以使用 if 条件设置 'n' 值。
因此您可以使用单个函数计算任何类型的利息。
Use the formula
A=P(1+r/n)^nt
where,
A :future value with interest
P :principle amount
r :annual interest(decimal)
n : no. of times interest is compounded per year
t : no. of years for which money is invested
Convert 'r' value to float value by dividing it by 100 after accepting int value from user. Provide radio button to select type of investment like quarterly, monthly, yearly etc accordingly you can set 'n' value by using if condition.
so you can calculate any type of interest using single function.