DEV Community

Tidy Cents
Tidy Cents

Posted on

Win-back offer break-even with BigInt: 'strictly more' is not the same as ceil()

A win-back test usually has two groups of lapsed customers: one gets a discount, one gets nothing. The question before you send anything: how many customers must come back in the offer group for it to beat the control group?

Example: margin per order $22.50, discount $10, so $12.50 left on a discounted order. 18 control customers return on their own: 18 × 22.50 = $405. Break-even is 405 / 12.50 = 32.4 customers.

Two traps:

  1. Floats. 405 / 12.5 is fine, but 0.1 + 0.2-style errors appear quickly once margins come from percentages. Keep everything in integer cents.
  2. Ceil vs strictly more. ceil(405 / 12.5) = 33 here, which happens to be right. But when the division is exact (say 400 / 12.50 = 32), ceil returns 32, and 32 customers only tie the control group. If the goal is to beat it, the answer is floor(target / margin) + 1.
// Minimum number of returning customers an offer group needs to beat a control group.
// All money in integer cents (BigInt), so 405.00 / 12.50 is never 32.399999...
function offerBreakEven({ marginCents, discountCents, controlReturns }) {
  const offerMargin = marginCents - discountCents;    // margin left on a discounted order
  if (offerMargin <= 0n) return null;                 // the offer can never pay back
  const target = BigInt(controlReturns) * marginCents; // what doing nothing earns
  // strictly more than the control group: smallest n with n * offerMargin > target
  return target / offerMargin + 1n;
}
function incremental({ marginCents, discountCents, controlReturns, offerReturns }) {
  return BigInt(offerReturns) * (marginCents - discountCents) - BigInt(controlReturns) * marginCents;
}
const ex = { marginCents: 2250n, discountCents: 1000n, controlReturns: 18 };
console.log(offerBreakEven(ex), incremental({ ...ex, offerReturns: 30 }), incremental({ ...ex, offerReturns: 40 }));
Enter fullscreen mode Exit fullscreen mode
33n -3000n 9500n
Enter fullscreen mode Exit fullscreen mode

30 returning customers lose $30.00 against the control group; 40 earn $95.00 more.

Test the definition, not just the example

for (let m = 1n; m < 400n; m += 7n) for (let d = 0n; d < m; d += 5n) for (let c = 0; c < 40; c += 3) {
  const n = offerBreakEven({ marginCents: m, discountCents: d, controlReturns: c });
  assert.ok(n * (m - d) > BigInt(c) * m);         // n beats the control group
  assert.ok((n - 1n) * (m - d) <= BigInt(c) * m); // n - 1 does not
}
Enter fullscreen mode Exit fullscreen mode

Two assertions pin the function to its definition: n wins, n − 1 does not. Any off-by-one (ceil instead of floor + 1) fails on the exact-division cases.

I use the same "minimum effect to break even" idea in a retention tool I work on: https://gettidycents.com/product/customer-retention-winback-profit-lab

Top comments (0)