The standard loan payment formula gives a level payment that pays a loan off exactly at the end of its term. The Consumer Financial Protection Bureau (CFPB) describes a typical fixed-rate mortgage that way: if you keep the loan for the full term and make all of your payments, you will precisely pay off the loan at the end of the loan term.

The formula's result almost never lands on a whole cent, though. A lender charges a payment rounded to the cent, and each month's interest is rounded to the cent too. Those small differences build up, so the balance after the last scheduled payment is usually a few cents above or below zero. The fix used in many amortization schedules is simple: the last payment is not the regular payment. It is whatever clears the remaining balance plus that month's interest.

This article shows how to build that into a JavaScript amortization schedule, using integer cents. All examples are hypothetical. Lenders can handle the final payment differently, so the loan agreement and the lender's own schedule are what apply to a real loan. This is general information about a calculation, not financial advice.

Why there is a residual

The level monthly payment for a loan of P, monthly rate r, and n payments is:

payment = P * r / (1 - (1 + r)^(-n)) 

Take a hypothetical $300,000 loan at 6.5% for 30 years (360 monthly payments). The exact payment is $1,896.204070..., which rounds to $1,896.20. Each month you pay about $0.004 less than the exact amount. Over hundreds of payments, with interest also rounded each month, the shortfall grows to a few dollars by the end.

The official commentary to Regulation Z recognizes this situation. It says that a final payment that differs from other regular periodic payments because of rounding to account for payment amounts including fractions of cents is still a regular periodic payment and need not be disclosed as a balloon payment. In other words, a slightly different last payment caused by cent rounding is expected, and it is not the same thing as a balloon payment.

Keep everything in integer cents

Floating-point dollars make rounding harder to control, so every amount below is an integer number of cents, stored as a BigInt. Interest for a month is the balance times the monthly rate, rounded half-up to the cent:

// Round a positive BigInt fraction num/den half-up. function divRoundHalfUp(num, den) { return (num * 2n + den) / (den * 2n); } // Monthly interest in cents. aprBps: APR in basis points (6.5% = 650). function interestCents(balanceCents, aprBps) { return divRoundHalfUp(balanceCents * BigInt(aprBps), 12n * 10000n); } 

The regular payment comes from the formula. It is computed once as a floating-point number and then rounded to the cent, which is fine because it is a single calculation, not a running total:

function paymentCents(principalCents, aprBps, n) { const P = Number(principalCents) / 100; const r = aprBps / 10000 / 12; const pay = (P * r) / (1 - Math.pow(1 + r, -n)); return { exact: pay, cents: BigInt(Math.round(pay * 100 + 1e-9)) }; } 

Let the last payment clear the balance

The loop runs the regular payment for payments 1 through n − 1. On payment n, it ignores the regular payment and charges the remaining balance plus that month's interest:

function schedule(principalCents, aprBps, n) { const { cents: pay } = paymentCents(principalCents, aprBps, n); let balance = BigInt(principalCents); const rows = []; for (let k = 1; k <= n; k++) { const interest = interestCents(balance, aprBps); let payment; let principal; if (k < n) { payment = pay; principal = pay - interest; } else { principal = balance; // pay off whatever is left payment = balance + interest; // remaining balance + final interest } balance -= principal; rows.push({ k, payment, interest, principal, balance }); } return rows; } 

Four hypothetical loans

Each loan below was run with the code above on Node 24. "Unadjusted end balance" is what is left if the regular rounded payment is charged all the way through payment n.

Loan Principal APR Payments Exact payment Rounded payment Last payment (adjusted) Difference Unadjusted end balance
A $10,000 6.00% 12 $860.664297 $860.66 $860.70 +$0.04 $0.04
B $25,000 7.99% 60 $506.790220 $506.79 $506.80 +$0.01 $0.01
C $300,000 6.50% 360 $1,896.204070 $1,896.20 $1,900.91 +$4.71 $4.71
D $5,000 4.90% 36 $149.630100 $149.63 $149.62 −$0.01 −$0.01

Two things stand out.

First, the residual can go either way. In loans A, B, and C the rounded payment is slightly too small, so the last payment is a bit larger. In loan D the rounded payment is slightly too large, so the last payment is one cent smaller, and the unadjusted schedule ends at −$0.01, a tiny overpayment.

Second, the size depends on the term and the amount. In these examples, the 12-month loan drifts by 4 cents, while the 30-year mortgage in loan C drifts by $4.71. Each regular payment in loan C is only about $0.004 below the exact payment, but that small shortfall is repeated over 359 payments and itself accrues interest.

Here are the first and last rows of loan C:

k | payment | interest | principal | balance 1 | 1,896.20 | 1,625.00 | 271.20 | 299,728.80 2 | 1,896.20 | 1,623.53 | 272.67 | 299,456.13 359 | 1,896.20 | 20.40 | 1,875.80 | 1,890.67 360 | 1,900.91 | 10.24 | 1,890.67 | 0.00 

With the adjustment, the principal column adds up to exactly $300,000.00, total interest is $382,636.71, and total paid is $682,636.71.

Checks worth adding

A schedule that adjusts the last payment should still be tested:

function checkSchedule(rows, principalCents) { const sum = (key) => rows.reduce((s, r) => s + r[key], 0n); const principalOk = sum('principal') === BigInt(principalCents); const endsAtZero = rows[rows.length - 1].balance === 0n; const rowsAddUp = rows.every((r) => r.payment === r.interest + r.principal); return { principalOk, endsAtZero, rowsAddUp }; } 

If principalOk fails, principal was lost or created by rounding somewhere in the loop. If endsAtZero fails, the last payment was not set to the remaining balance plus interest.

What this model leaves out

  • Other rounding rules. Some systems round half-to-even, or round interest differently. A different rule can change the residual by a cent or two.
  • Day-count conventions. This model uses a monthly rate of APR ÷ 12. Loans that accrue interest by actual days can behave differently.
  • Fees, escrow, and extra payments. Taxes, insurance, fees, and extra principal payments are not included. Extra principal can end the loan early, and then the "last" payment is whichever payment clears the balance.
  • Balloon loans. A balloon payment is a large final payment built into the loan's terms. It is not a rounding residual.

To try a schedule with your own numbers, FINORA's personal loan calculator runs in the browser.

Sources

AI disclosure: this post was drafted with AI assistance. The code was run on Node 24, and the figures shown are copied from that run.

Disclosure: I'm the maker of FINORA, a set of free browser-based finance calculators. No affiliate links.