Spielerando

Fix prices and coins that add up to odd values like 0.30000000000000004

Add ten small amounts and the total is a hair off, so a price will not match, a purchase button stays grey, or the shop shows a long tail of digits. This entry shows how to make the AI keep money exact and round the way players expect.

Why this works

Computers think in halves, quarters and so on, so most tenths cannot be stored exactly, and every sum picks up a tiny error. Counting in whole small units keeps every step exact. The messy conversion then happens only where people look.

When not to use it

Whole units are not worth it for numbers that are not money, such as speed, distance or a chance. Those are measurements, where a tiny error is harmless. It also fails for quantities that grow beyond what whole numbers can hold exactly.

In the full entry

  • What to build, step by step
  • Starting values and the reason for each
  • 3 common mistakes and the fix
  • A diagram of every state
  • 24 lines of example code with 4 checks that pass
  • How your AI shows you that it works

Say this to your AI

Use the Spielerando entry "Fix prices and coins that add up to odd values like 0.30000000000000004" (read_entry money-adds-up-to-0-30000000000000004) in my game. Build it step by step, and show me how you checked that it works.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP