Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Four-weekly is not monthly: a billing-period bug hiding in plain sight

A $10 subscription billed every four weeks and a $10 subscription billed monthly should not produce the same annualized total. Using a 52-week comparison convention, the first is $130 a year; the second is $120. A dropd

Four-weekly is not monthly: a billing-period bug hiding in plain sight

A $10 subscription billed every four weeks and a $10 subscription billed monthly should not produce the same annualized total.

Using a 52-week comparison convention, the first is $130 a year; the second is $120. A dropdown label can hide a 10% difference.

Honest Little Apps publishes MoneyShield. This article uses its public App Store screenshots as product context; the JavaScript below is an independent example, not a claim about the app's internal implementation.

Show the decision, not just the number

Official MoneyShield App Store screenshot showing its subscription-management experience
Official MoneyShield App Store screenshot showing another subscription-review screen

A comparison needs three separate concepts: the amount per charge, the billing interval, and the annualized estimate. Calling all three a monthly cost creates ambiguity.

Keep the period explicit

For a simple comparison tool, use named periods and integer minor units. This example assumes a currency with two decimal places and requires all amounts in one currency.

const cyclesPerYear = Object.freeze({
  weekly: 52,
  fortnightly: 26,
  everyFourWeeks: 13,
  monthly: 12,
  quarterly: 4,
  halfYearly: 2,
  yearly: 1
});

function annualizedCents(priceCents, period) {
  if (!Number.isSafeInteger(priceCents) || priceCents < 0) {
    throw new RangeError('Enter a non-negative integer amount in cents.');
  }
  if (!Object.hasOwn(cyclesPerYear, period)) {
    throw new RangeError('Choose a supported billing period.');
  }
  const result = priceCents * cyclesPerYear[period];
  if (!Number.isSafeInteger(result)) {
    throw new RangeError('Amount exceeds the supported range.');
  }
  return result;
}

console.assert(annualizedCents(1000, 'everyFourWeeks') === 13000);
console.assert(annualizedCents(1000, 'monthly') === 12000);
console.assert(annualizedCents(0, 'yearly') === 0);

Keep the integer result for calculations. Format it for display at the boundary. For example, 13,000 cents divided by 12 gives a monthly equivalent of about $10.83; it does not change the actual $10 charge every four weeks.

An annualized estimate is not a calendar forecast

The 52-week convention covers 364 days. Depending on the start date and interval, a calendar-year window can contain a different number of charges. A cash-flow forecast needs the actual next charge date and the provider's recurrence rules.

Use β€œEstimated annual cost” for the comparison. Reserve β€œCharges due this year” for a date-based schedule. Monthly schedules also need an explicit policy for dates such as the 31st; multiplying by 30 days does not implement calendar months.

Five checks worth putting beside the happy path

  • Empty input: keep β€œnot entered” distinct from a genuine zero. Do not let an empty string silently become zero.
  • Invalid amounts: reject negatives, non-finite values and unsupported precision before converting to cents.
  • Mixed currencies: group totals by currency unless an explicit exchange-rate conversion is part of the product.
  • Edited inputs: clear or visibly invalidate an old result as soon as an amount or period changes.
  • Different units: display β€œper charge,” β€œannualized,” and β€œmonthly equivalent” where they are used, not only in a tooltip.

A useful regression case is two $10 entries: one every four weeks and one monthly. The combined annualized cost should be $250 and the monthly equivalent about $20.83.

Turn the comparison into one next action

A large annualized number alone does not help someone finish the task. A review flow can ask: keep it, review it later, or open the official cancellation route. A cancellation request is not the same as a confirmed cancellation.

MoneyShield's App Store listing describes subscription reviews, renewal reminders, a What If planner and guided cancellation routes. It does not cancel subscriptions automatically or guarantee refunds.

Explore MoneyShield for iPhone and iPad. Free download with optional paid Plus features; see the store for current availability and pricing.

For a browser-only example, try the subscription cost calculator. No app is needed to use it.

What recurrence edge case has caused the most trouble in a product you have built?

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.