How to do recurring deposit calculations accurately [closed]

自古美人都是妖i 提交于 2019-12-13 09:03:51

问题


I'm new to ruby on rails and my doubt is how to do recurring deposit calculations. i have used one formula to calculate monthly interest and that is working for first month and not calculating accurate interest for the upcoming months(2nd month, 3rd month ... n months). Formula i used is given below.

total = depositamount * rate of interest * 30 / 365

Kindly help me to solve this issue. -Thanks.


回答1:


If the first month calculation is correct and subsequent months are wrong, are you saying that you want a compound interest formula? (i.e. in month 2 you calculate interest on principle + previous months' interest)

toal = deposit_amount * (rate_of_interest*30/365)**month_number



回答2:


Let's assume that you're looking for an iteration : you want a simple calculation ( with a rate of interest which doesn't change ) to apply on a depositamount which changes every months. As your asking is quite unclear ( that's why you're getting these downvotes ), you might want to clarify it a lot if the following is not answering your question.

monthly_deposits = [deposit1, deposit2, deposit3... ]

Ruby

monthly_deposits.each do |deposit|
  puts deposit * rate of interest * 30/365
end

Rails

   <% monthly_deposits.each do |deposit| %>
      <%= deposit * rate of interest * 30/365 %>
   <% end %>

But if that's what you were asking, you probably need to read some tutoriels.



来源:https://stackoverflow.com/questions/23626271/how-to-do-recurring-deposit-calculations-accurately

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!