- 매월 이자 반올림 누적으로 마지막 정상 회차 뒤 수십원(원금 62·이자 1) 추가 회차 생기던 문제. 잔액<=월상환금이면 마지막 회차로 남은 잔액을 한 번에 정산(은행 동일) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -76,14 +76,18 @@ export function loanSchedule(w, now = currentYm(), cap = 600) {
|
|||||||
if (fixed > 0) {
|
if (fixed > 0) {
|
||||||
while (bal > 0 && rows.length < cap) {
|
while (bal > 0 && rows.length < cap) {
|
||||||
const interest = Math.round(bal * r)
|
const interest = Math.round(bal * r)
|
||||||
let principal = fixed - interest
|
if (fixed <= interest) {
|
||||||
if (principal <= 0) {
|
|
||||||
// 상환금이 이자에 못 미침(데이터 이상) → 더 진행 못함
|
// 상환금이 이자에 못 미침(데이터 이상) → 더 진행 못함
|
||||||
rows.push({ label: label(y, m), principal: Math.max(0, principal), interest, total: fixed, balance: bal })
|
rows.push({ label: label(y, m), principal: 0, interest, total: fixed, balance: bal })
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
principal = Math.min(principal, bal)
|
// 마지막 회차: 남은 잔액 한 번에 정산(은행은 잔여 반올림을 마지막 납입에 합산 → 추가 회차 안 생김)
|
||||||
bal = Math.max(0, bal - principal)
|
if (bal <= fixed) {
|
||||||
|
rows.push({ label: label(y, m), principal: bal, interest, total: bal + interest, balance: 0 })
|
||||||
|
break
|
||||||
|
}
|
||||||
|
const principal = fixed - interest
|
||||||
|
bal = bal - principal
|
||||||
rows.push({ label: label(y, m), principal, interest, total: principal + interest, balance: bal })
|
rows.push({ label: label(y, m), principal, interest, total: principal + interest, balance: bal })
|
||||||
;({ y, m } = addMonths(y, m, 1))
|
;({ y, m } = addMonths(y, m, 1))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user