Debug a Cart Total That Comes Out One Cent Short

Last updated: November 29, 2026

Quick Overview

A cart service computes totals with floats and occasionally charges customers a cent less than the receipt shows. Find the root cause, fix the money math, and write tests that would have caught it.

Walmart Labs
Software Engineering Fundamentals
Software Engineer
Walmart Labs
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


A cart service computes totals with floats and occasionally charges customers a cent less than the receipt shows. Find the root cause, fix the money math, and write tests that would have caught it.

Checkout correctness is non-negotiable at Walmart's scale, where a one-cent bug repeated across millions of orders becomes a finance and compliance problem. Walmart Labs phone screens use this debugging scenario to see if you know binary floating point pitfalls, pick a rounding rule deliberately, and test boundaries.

What the Interviewer Expects
  • Reproduce the bug with a minimal failing example
  • Explain binary floating point representation error
  • Distinguish truncation from rounding as a second bug
  • Switch to integer cents or Decimal with an explicit rounding mode
  • Add tests at rounding boundaries and for empty carts
Key Topics to Cover
floating point
debugging
unit testing
money handling
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Should tax be rounded per line or on the cart subtotal, and who decides?
  • How would you migrate stored float prices without changing any customer's charge?
  • How would you handle currencies with zero or three decimal places?
  • How would you find other places in the codebase with the same bug?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Lines are (unit_price, qty) where the price arrives as a string from the catalog, sometimes with sub-cent digits for bulk items. Tax is a percentage applied to the subtotal. The total must be exact ...

High-Level Design

Root cause one: 0.29 cannot be represented exactly in binary, so 0.29 * 100 is 28.999999999999996. Root cause two: int() truncates, so that becomes 28 instead of 29. Each alone is subtle, and ...


Submit Your Answer
Markdown supported