1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Fix currency formatting for 0 values (#1276)

* Fix currency formatting for 0 values

* Fix loan payment calculation for zero interest rate
This commit is contained in:
Zach Gollwitzer 2024-10-09 18:11:36 -04:00 committed by GitHub
parent a2ab217925
commit 0a303ccbd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View file

@ -8,7 +8,11 @@ class Loan < ApplicationRecord
annual_rate = interest_rate / 100.0
monthly_rate = annual_rate / 12.0
payment = (account.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
if monthly_rate.zero?
payment = account.original_balance.amount / term_months
else
payment = (account.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
end
Money.new(payment.round, account.currency)
end