Rules›northwind-amount-as-float
northwind-amount-as-float
warningnorthwind/correctness/amount-as-float
The amount handed to charges.create comes from a float expression (a price in dollars, a tax multiplier, a division) instead of an integer number of cents.
21
codebases affected, of 58
36%
of everything we scanned
▼14
points since the first docs fix
1
docs commits aimed at this
Where it’s failing
amount is a non-integer value — Northwind expects an integer number of minor units.
what we find
what we change it to
Keep money in integer minor units end to end and round once at the boundary: Math.round(dollars * 100) for input, Math.round(cents * rate) for derived amounts. Never let a float reach charges.create.
Metadata
- Category
- correctness
- Type
- suggestion
- Severity
- warning
- Recommended
- yes
- Languages
- javascriptpython
Live telemetry
21 / 58 scans
Fired in 36% of scanned codebases.
After every docs commit
docs(api): minor-units callout on the charges reference
4af07c2 · merged 6 weeks ago · PR by your team, scored by api-doctor
A fix for your docs page
Wherever this rule fires, a page on your docs site taught it. api-doctor writes the edit and opens it as a pull request on your docs repo — you review and merge.
Draft a docs fix for this rule
api-doctor writes the docs change from the fire pattern — you review it
History
Flag Math.round(x * 100) as a float path, not a fix
3 weeks ago · via GitHub
Track amounts across destructured order objects
9 weeks ago · via GitHub