Back to Blog

Why Your AI's Revenue Is 100 Times Too Big

Asked for revenue and got $8.4 million. The column holds cents, the way Stripe stores 1999 for $19.99. SUM added the cents and the AI read the result as dollars.

You ask: "What's our revenue?" The AI says $8.4 million. Finance has $84,000. The query is one line and it runs cleanly.

SELECT SUM(amount) FROM orders

amount is an integer. A $19.99 order is stored as 1999, which is how Stripe and a lot of payment tables keep money out of floating point. SUM adds those integers. 8,400,000 cents is $84,000. The AI put a dollar sign on the cents.

The number is exact. The unit is wrong.

Nothing in the result says "cents." An integer total looks like a dollar total, especially once it is big enough to be a believable revenue figure.

-- what the column actually holds
SELECT amount FROM orders ORDER BY created_at DESC LIMIT 5
-- 1999, 499, 2500, 1999, 1000

If those are the prices you charge, the column is in cents. If you see 19.99, it is already in dollars and dividing by 100 is the bug in the other direction.

This is not a FLOAT total drifting by a few cents. A factor of 100 does not come from binary rounding. It is also not dollars added to euros, except at the edge: zero-decimal currencies such as JPY are stored as the whole amount, so 500 means 500 yen. Dividing that row by 100 reports ¥5.

The same scale error hits filters. "Orders over $100" written as WHERE amount > 100 keeps every order over one dollar.

How to fix it

-- dollars, for a currency that has cents
SELECT SUM(amount) / 100.0 AS revenue_usd
FROM orders
WHERE currency = 'usd'

-- "over $100" in a cents column
SELECT COUNT(*) FROM orders WHERE amount >= 10000

Use / 100.0, not / 100. Two integers divide to an integer in Postgres and SQL Server, so $19.99 becomes $19 before you ever format it. That is the percentage-comes-back-as-0 bug, one step later.

Say the unit in the answer. "SUM(amount) / 100, USD, cents column" is a number you can check. "Revenue: 8400000" is not.

How to catch it

SELECT MIN(amount) AS smallest, ROUND(AVG(amount), 0) AS typical, MAX(amount) AS largest
FROM orders
WHERE amount > 0

Compare typical to a price you know. A typical value of 2000 on a twenty-dollar product is cents. A typical value of 20 is dollars. Then check the AI's total against SUM(amount) / 100.0 for that same filter. A clean 100× gap is this bug.

The prompt that heads this off

Before you sum or filter an amount column, look at a few raw values and
decide whether they are major units (19.99) or minor units (1999 = $19.99).
If they are cents, divide by 100.0 and say so. Write thresholds in the same
unit as the column. Do not divide zero-decimal currencies (JPY) by 100.

The short version

An integer amount is often cents. SUM of that column is a cent total, and a dollar sign does not change the unit. Divide by 100, keep filters in cents, and skip the divide for currencies that have no minor unit.


Read-only MCP gateway: mcpserver.design.

Related reading: