Break-even looks like one division: fixed costs divided by what each sale leaves (price minus unit cost). The bugs are in the details around it: floats, rounding direction, and a percentage that is really a ratio of two money amounts.
Keep money in integer cents
const fixed = 960000n; // $9,600.00 const price = 1200n; // $12.00 const unitCost = 480n; // $4.80 const contribution = price - unitCost; // 720n = $7.20 BigInt (or plain integers below 2^53) means $12.00 - $4.80 is exactly $7.20, not 7.199999999999999.
Units: round up, never down
960000 / 720 = 1333.33…. Selling 1,333 units leaves you 240 cents short. Break-even is the first whole unit at which costs are covered, so it is a ceiling division:
const ceilDiv = (a, b) => (a + b - 1n) / b; // a, b > 0 const units = ceilDiv(fixed, contribution); // 1334n Math.round would give 1,333 here, and Math.floor (or plain BigInt division) is short whenever there is a remainder.
Sales: two answers, both correct
- From whole units:
1334n * price= $16,008.00 - From the margin ratio:
fixed * price / contribution= $16,000.00 exactly
They differ only because of the rounding up. Show both, and label which one is which, otherwise someone will report the $8 difference as a bug.
Margin of safety as basis points
const sales = 1900000n; // $19,000.00 const be = fixed * price / contribution; // 1600000n const bps = (sales - be) * 10000n / sales; // 1578n = 15.78% Integer basis points avoid printing 15.789473684210526%. Decide explicitly whether a ratio rounds down (conservative for safety margins) and write it in a test.
Tests worth having
- contribution ≤ 0 → no break-even (return an explicit state, not
Infinity) - exact division (e.g. fixed $7,200, contribution $7.20 → exactly 1,000 units)
- one cent below and above an exact boundary
- current sales below break-even → negative margin of safety, shown as such
We use these rules in the free Break-Even Calculator, which shows each formula next to its result.


