DEV Community

Cover image for Credit card interest in code: why a 2% minimum payment takes 110 years at 22.36%
Jeremiah Say
Jeremiah Say

Posted on

Credit card interest in code: why a 2% minimum payment takes 110 years at 22.36%

Put $5,000 on a credit card at 22.36% and pay only a minimum of 2% of the balance (at least $20). How long until it's gone?

110 years and 3 months, with $56,440 of interest.

That isn't a bug in my code. It's the minimum-payment formula from Regulation Z's own sample, run with the Federal Reserve's latest average rate for cards that are charged interest. Switch to another common formula, 1% of the balance plus that month's interest, and the same $5,000 takes 19 years and 3 months.

I built a credit card interest calculator that follows the rules US card issuers use for the repayment estimate printed on every statement. This post covers the arithmetic, the rounding rules and the tests, and why one formula ends and the other nearly doesn't.

Where 22.36% comes from

The Federal Reserve's G.19 release reports two average card rates each quarter. For 2026 Q3 (released 6 November 2026), the average was 21.19% across all accounts and 22.36% on accounts that were charged interest. The second one is the honest default, because accounts paid in full pay no interest at all.

The tool keeps both in one constant, and the page build stops if they don't match the saved release:

export const G19 = { q: '2026 Q3', released: '6 Nov 2026', all: 0.2119, int: 0.2236 };
Enter fullscreen mode Exit fullscreen mode

The rules: Regulation Z, Appendix M1

Every US card statement has to show a "Minimum Payment Warning" box: how long minimum payments would take and what they'd cost (12 CFR 1026.7(b)(12)). Appendix M1 says how issuers must work it out: a daily rate of APR ÷ 365, months of 365 ÷ 12 days, no new purchases, and no grace period.

Those two rules collapse into something familiar:

export const DAYS = 365 / 12;                  // 30.41667 days
export const mRate = apr => apr / 365 * DAYS;  // ... which is exactly apr / 12
Enter fullscreen mode Exit fullscreen mode

So the projection really is APR ÷ 12 per month. I still write it the regulation's way, so each line of code can be checked against the text.

The loop

One month: interest on the balance, rounded to the cent, then the payment. The minimum is worked out on the balance before that month's interest, in the order Appendix M2's sample code uses:

const c2 = v => Math.round((v + Number.EPSILON) * 100) / 100;

function run(bal0, apr, pay, { max = 1200 } = {}) {
  let bal = c2(bal0), m = 0, tot = 0, totI = 0;
  while (bal > 0.004 && m < max) {
    m++;
    const interest = c2(bal * mRate(apr)), due = c2(bal + interest);
    let p = pay(bal, interest, m);
    if (!(p > interest) && p < due) return { never: true, months: m };
    if (p >= due) p = due;                     // the last payment clears it
    tot += p; totI += interest; bal = c2(due - p);
  }
  return bal > 0.004 ? { never: true, capped: true, months: m }
                     : { months: m, total: c2(tot), interest: c2(totI) };
}
Enter fullscreen mode Exit fullscreen mode

Two details matter:

  • The never guard. If a payment doesn't beat the month's interest, the balance can't fall. Without the guard, the loop spins until max and reports a number that means nothing.
  • Number.EPSILON in the rounding. Math.round(1.005 * 100) / 100 gives 1, not 1.01, because 1.005 is stored as 1.00499999…; adding Number.EPSILON first gives 1.01. Over 1,323 months, cent errors add up. (I wrote about this trap in testing calculator formulas.)

Why 2% nearly never ends

Here are the first three months of $5,000 at 22.36% on the 2% minimum:

Month Balance Interest Payment Off the balance
1 $5,000.00 $93.17 $100.00 $6.83
2 $4,993.17 $93.04 $99.86 $6.82
3 $4,986.35 $92.91 $99.73 $6.82

A month's interest is 22.36 ÷ 12 = 1.863% of the balance. A 2% payment beats it by 0.137 points, so less than $7 of each $100 payment reaches the balance. And because the minimum shrinks with the balance, the gap never widens.

Push the APR to 24% and 2% exactly equals the interest. Above that, on any balance of $1,000 or more (where 2% is above the $20 floor), the balance never falls. At 23.5% the tool hits its 300-year cap. The Fed's average sits only about 1.6 points below that line.

The 1%-plus-interest formula can't get stuck. By definition it pays the interest and then 1% of the balance, so the balance always falls:

Balance 1% + interest Interest paid 2% of balance Interest paid
$1,000 5 years 11 months $788 12 years 2 months $1,907
$5,000 19 years 3 months $8,241 110 years 3 months $56,440
$10,000 25 years $17,558 152 years 5 months $124,609

At 22.36%, minimum payments only, no new purchases, Appendix M1 rules.

Your card agreement sets your real formula. The tool lets you type your own percentage, floor and whether interest is added.

Rounding the way a statement does

A statement doesn't print "1,323 months". Section 1026.7(b)(12) says under 2 years is shown in months, and anything else in years, rounded to the nearest whole year:

export const shown = months =>
  months < 24 ? `${months} months` : `${Math.round(months / 12)} years`;
Enter fullscreen mode Exit fullscreen mode

Appendix M1 prints its own examples: 28 months shows as "2 years", 30 months as "3 years". They're in the test table below. One more rule from the regulation: the "pay this much to finish in 3 years" line appears only when the estimate is more than 3 years after rounding. That's easy to get wrong with a months > 36 check, because 37 to 41 months round to 3 years.

The statement: average daily balance

The repayment estimate assumes equal months. A real statement doesn't. Each day's balance is charged at APR ÷ 365, which works out as average daily balance × daily rate × days in the cycle:

export function statement({ start, tx = [], days, apr }) {
  // tx: [{ day, amt }] with purchases +, payments −; day 1 = first day of the cycle
  const byDay = new Map();
  for (const t of tx) byDay.set(t.day, c2((byDay.get(t.day) || 0) + t.amt));
  const steps = [{ day: 1, bal: c2(start + (byDay.get(1) || 0)) }];
  byDay.delete(1);
  [...byDay.keys()].sort((a, b) => a - b)
    .forEach(d => steps.push({ day: d, bal: c2(steps.at(-1).bal + byDay.get(d)) }));
  steps.forEach((s, i) => { s.n = (steps[i + 1]?.day ?? days + 1) - s.day; });
  const adb = c2(steps.reduce((a, s) => a + s.bal * s.n, 0) / days);
  const interest = Math.ceil(adb * apr * days / 365 * 100 - 1e-6) / 100;  // rounded UP
  return { adb, interest };
}
Enter fullscreen mode Exit fullscreen mode

On a $1,200 balance in a 30-day cycle at 22.36%, with $64.20 spent on day 8, a $300 payment on day 15 and $129.99 on day 22, the average daily balance is $1,128.22 and the interest is $20.74. Move the same payment to day 28 and it's $23.13. The earlier a payment lands, the more days it lowers the balance.

The Math.ceil(... - 1e-6) is there because the textbook this follows rounds interest up to the next cent. Without the small offset, a result that should be exactly 31.80 but comes out of floating point as 31.800000000000001 would round up to 31.81.

Tests: the sources' own worked examples

A formula that looks right isn't enough. The page's test table runs printed examples through the tool's code:

Example Source Source's answer Tool
Average daily balance, a $120 payment and 4 purchases OpenStax 6.10, ex. 6.93 $442.39 $442.39
$2,765.00 at 13.99% for 30 days OpenStax 6.10, ex. 6.94 $31.80 $31.80
$789.30 at 17.99% for 31 days OpenStax 6.10, ex. 6.94 $12.06 $12.06
A November with 10 transactions at 16.9% OpenStax 6.10, ex. 6.96 $28.80 $28.80
2.5% minimum on $1,309.00 OpenStax 6.10, ex. 6.97 $32.73 $32.73
28 months shown on a statement Reg Z Appendix M1 (b)(5) 2 years 2 years
30 months shown on a statement Reg Z Appendix M1 (b)(5) 3 years 3 years

The 10-transaction example is the useful one. It catches off-by-one errors in how many days each balance lasts (days + 1 - day for the last step), which no single-transaction test can.

APR isn't the yearly cost

An APR is a nominal rate. Charged daily on a balance that includes past interest, 22.36% grows a balance by 25.05% over a year:

const daily = (1 + apr / 365) ** 365 - 1;   // 0.2505 at 22.36%
Enter fullscreen mode Exit fullscreen mode

Try it

The credit card interest calculator has four tabs: Payoff (a fixed payment or the payment for a deadline), Minimum (laid out like the statement box), Statement (your own transactions) and Transfer (a balance transfer offer against staying put). Everything runs in your browser. For what an unpaid balance grows to, there's the compound interest calculator.

Every Toggle9 tool cites its sources and is re-checked on a schedule: how we check our tools explains the tests. The 22.36% default is re-checked when the Fed publishes the next quarter.

AI assistants helped build the tool and draft this post. The figures come from the tool's code run on 20 November 2026.

Top comments (0)