Handle money amounts correctly in code
Prompt that reviews how money amounts are stored and rounded and sets rules with test cases. Paste it into an AI tool of your choice, which then reviews how money amounts are handled.
- Topic
- Apps & prototypes
- Type
- Prompt
- Level
- Intermediate
- Time
- about 10 min
Results depend on the tool, the model and what you enter.
Result preview
Example: written by our editors, not real AI output.
Finding: cart.js, line 42 → price stored as float Rule: store amounts as whole cents, round only in calculate_total() Test: €100.00 in 3 instalments → 33.34 + 33.33 + 33.33 = 100.00 Question for the tax adviser: round tax per line or on the total?
Fill in
What you type stays in this browser window. We store and send nothing.
- online shop with a cart
- invoicing tool
- subscription management
- booking system
- marketplace with commissions
- JavaScript or TypeScript
- Python
- Java
- PHP
- SQL in the database
- totals are off by one cent
- discounts produce odd amounts
- several currencies
- tax amount is wrong
- nothing yet, just prevention
Your prompt
You have edited the prompt. Changes in the fields above no longer overwrite it.
This is an instruction for an AI, not the result itself.
Where this prompt works
These AI tools are a good fit for this prompt:
How to use it
- Fill in the fields or tap a suggestion. Leave out names, addresses and other personal data.
- Copy the finished prompt into an AI tool of your choice.
- Split 100.00 into three and add the parts back up. If the result is not exactly 100.00, a rule for the remainder is missing.
Why does this work?
Floating-point numbers cannot represent many decimal amounts exactly, and every place rounds differently. A fixed data type, one rounding rule in one place and tests for edge cases prevent differences that are painful to track down later.
Tips
- General technical help, not tax advice. If you are unsure how taxes must be rounded, check with your tax adviser.