DEV Community
How to compute the smallest safe deposit for a big order (integer cents, no AI)
Floating-point money is a classic bug source. Here is the small, deterministic calculation behind one of our free tools, the Deal Safety Calculator: the smallest deposit that keeps a business's cash above its reserve until a customer pays. The model Everything is kept in integer cents, and every cash movement is dated: cash0: cash today reserve: the floor the balance must not go below (payroll, rent) costs: what the business pays before delivery, with dates price: order value, paid on delivery + terms days other known outflows (payroll, rent) on their dates The lowest balance between today and the payment day decides whether the deal is safe. // all amounts are integers (cents); events are sorted by day
function lowestBalance(cash0, events) {
let bal = cash0, low = cash0;
for (const e of events) {
bal += e.amount; // negative = outflow
if (bal < low) low = bal;
}
return low;
}
// smallest deposit (in cents) that keeps the low point >= reserve
function minDeposit(cash0, reserve, events, price) {
const low = lowestBalance(cash0, events);
const gap = reserve - low; // how far below the floor we dip
if (gap <= 0) return 0; // already safe, no deposit needed
return Math.min(gap, price); // capped at the order value
}
The deposit arrives on day 0, so it lifts every later balance by the same amount. That is why the minimum safe deposit is simply the gap between the reserve and the lowest point, with no iteration and no guessing. Worked example A $40,000 order, $26,000 of costs paid before delivery, Net 60. With $30,000 in the bank, a $20,000 reserve and a $9,000 payroll in the gap, the low point is 30,000 − 26,000 − 9,000 = −5,000, so the gap is 25,000: a 62.5% deposit, or shorter terms that move the payment before payroll. Why not let an LLM do it? Ask a chatbot the same cash question twice and you can get two answers. Money decisions need the same answer every time, with the working shown. Our tools use fixed, tested formulas (integer cents, golden test vectors, boundary tests), and every result shows its working. Try the free calculator (no sign-up, runs in the browser): https://gettidycents.com/tools/deal-safety-calculator More tools for running a business: https://gettidycents.com/tools
Powered by Readybot.io
External Link
Platform
You are about to visit:
https://example.comThis will open in a new tab. Make sure you trust this link.