Group
  • Database

    Stop storing money as floats

    Finds every money value stored or calculated as a floating point number and converts it to integer cents or a decimal type.

    • Improve quality
    • Debug & fix
    • Intermediate
    • General

Free Prompt

Find every place my app stores, calculates, or compares money as a floating point number and fix it. Check: database columns for prices, amounts, totals, balances, credits, and fees (look for float, double, or real column types), JavaScript variables that hold prices and do arithmetic with plain number math, comparisons between money values using === or > on floats, and any place a price from the client is used directly in a calculation. Fix each one: database money columns become integer cents (or the smallest currency unit) or a proper decimal/numeric type, never float. In JavaScript, do money math in integer cents or use a decimal library like Dinero.js or decimal.js. Format for display only at the edge, when rendering to the user. Round explicitly and state the rounding rule wherever a calculation can produce a fraction (percentages, tax, proration). Do not change any prices users currently see. The migration must preserve existing values exactly: convert stored floats to the new representation with an explicit conversion, and show me a sample of before-and-after values to confirm. Do not change the API response shape without telling me. List every column and code path you changed, the conversion applied, and a test case that would have produced a rounding error before (like 0.1 + 0.2 !== 0.3) and is now exact.

What This Does / How This Helps

Replaces every float that touches money with integer cents or a decimal type, in the database and in code. Floats cannot represent most decimal values exactly. 0.1 plus 0.2 is 0.30000000000000004 in JavaScript. That is funny until it is a customer's invoice total that disagrees with Stripe by a cent, a balance that goes negative by 0.0000001, or a comparison that silently fails and lets a discount apply twice. AI assistants generate float columns and plain number math by default because it looks natural. This prompt finds every instance, converts storage and arithmetic to exact representations, and gives you the rounding-error test that proves the fix.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts