Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Engineers keep introducing float and double for monetary and quantity fields across many services, causing reconciliation incidents. What would you put in place organization-wide, and why does Java make this mistake easy?

Java makes the mistake easy because a literal such as 9.99 is a double and double has operators, while BigDecimal has only methods and feels heavy. Organisation-wide, I would standardise a shared Money and Quantity type with clear serialisation rules (strings or integer minor units in JSON), add automated checks that flag float and double on monetary fields and in API schemas, decide rounding modes and scales once with the domain owners, and track reconciliation differences as a metric so everyone can see the cost and the progress.

Why this question is asked

When the same bug keeps coming back across many services, the problem is no longer the individual engineers; it is that the easy path leads to the bug. A senior engineer's job is to change the easy path. Interviewers ask this question to see whether we can diagnose the root cause in the language and the platform, and then put in place a combination of tooling, shared code and measurement that actually changes behaviour across teams. In this answer, we will look at why Java nudges people toward double, explain what the bug really costs, and then go through the shared types, the automated checks, the rounding decisions and the metrics that together fix it.

1Why Java Makes This Mistake Easy

The language puts double on the shortest path. A decimal literal such as 19.99 is a double without any suffix, the arithmetic operators work on it, and it is fast and familiar from school maths. BigDecimal, the exact decimal type, is a library class: no literals, no operators, and every step is a method call that needs a rounding decision.

Java
double total = price * quantity * 1.2; // natural to write, and wrong for money
BigDecimal exact = price.multiply(BigDecimal.valueOf(quantity))
.multiply(new BigDecimal("1.2"))
.setScale(2, RoundingMode.HALF_EVEN); // correct, but much heavier

On top of that, many JSON libraries and JavaScript clients turn numbers into doubles by default, ORMs map a database NUMERIC column to whatever type the entity declares, and most tutorials use double for simplicity. So an engineer who is in a hurry, or new to payments, writes double, and every test with round numbers passes.

2What the Bug Really Costs

Binary floating point cannot represent most decimal fractions exactly, so 0.1 + 0.2 is 0.30000000000000004 and repeated operations drift. Individually the errors are tiny, but money is summed, rounded and compared with other systems, so a cent appears or disappears in a statement, a ledger fails to balance, or a reconciliation job flags thousands of mismatches. Each incident costs engineering time to investigate, finance time to correct and, in regulated businesses, possibly reporting. Explaining that cost in concrete terms is what earns the platform work a place on the roadmap.

3Make the Right Path the Easy Path

The core of the plan is a small shared library owned by a platform team. It provides a Money type, an amount in exact minor units or BigDecimal plus a currency, and a Quantity type for measured amounts with a unit and a fixed scale. These types offer the operations people actually need, plus, times, allocate and percentage of, with the rounding inside, so using them is shorter than writing BigDecimal chains by hand.

Java
Money price = Money.of("19.99", "EUR");
Money total = price.times(3).plusPercent(new BigDecimal("20")); // 71.96 EUR with the platform's rounding rule
String json = mapper.writeValueAsString(total); // {"amount":"71.96","currency":"EUR"}

The library also fixes serialisation. In JSON, amounts travel either as decimal strings such as "71.96" or as integer minor units such as 7196, always with the currency, never as floating numbers. Ready-made Jackson modules, JPA converters and OpenAPI schema fragments mean that a team adopting the type gets correct storage and correct APIs without extra decisions. (The method names here are illustrative; the point is that the shared type hides the rounding and serialisation rules.)

4Automated Checks That Catch Regressions

Guidelines alone do not survive twenty teams and staff turnover, so we add checks that run on every build. Static analysis rules in the shared build configuration flag float and double fields, parameters and return types whose names look monetary, such as amount, price, fee, total or balance; this can be written as an ArchUnit test, a custom Error Prone check or a PMD rule. A schema linter for OpenAPI specifications flags monetary properties declared as type number, and database migration reviews flag FLOAT or DOUBLE PRECISION columns for money.

We roll the checks out in two phases. First they report findings across all repositories, which gives an inventory and a baseline. Then, once a team has fixed its existing findings, the rule becomes build-failing for that repository, so the count can only go down.

Step throughRolling out the money rules
  1. Publish Money and Quantity librarywith Jackson, JPA and schema support
  2. Agree rounding and scale ruleswith finance and domain owners
  3. Run checks in report modeinventory per team, baseline metric
  4. Teams migrate their findingshighest-risk flows first
  5. Switch checks to build-failingnew code cannot regress
  6. Track reconciliation differencesshow cost and progress monthly

6 steps in order. Play them, or step through them one at a time.

5Deciding Rounding Once, With the Domain Owners

Many of these incidents are not only about types; they are about each service rounding at a different point, with a different mode. One service rounds tax per line with HALF_UP, another rounds the total with HALF_EVEN, and the results differ by a cent. These are business decisions, sometimes set by regulation or contracts, so engineers should not invent them per service. I would run a short decision process with finance and the product owners, record the rules for each operation (scale, rounding mode, where rounding happens) in one document, and implement them once in the shared library, with tests that encode real examples from finance.

6Measuring the Problem and the Progress

Finally, we make the problem visible. Reconciliation jobs already compare systems, so we publish their results as metrics: the number of mismatched records and the total absolute difference per day, per service pair. We also track incidents tagged as numeric or rounding issues and the count of static analysis findings per team. These numbers show leadership why the work matters, show teams where to focus, and tell us when the problem is actually solved, rather than assumed solved because a guideline was published.

7Follow-up questions

How would you convince teams with full roadmaps to migrate?

With their own numbers and a low cost of change. The inventory shows each team how many findings they have and which flows they touch, the reconciliation metric shows the real cost, and the shared library with examples makes each fix small. I would prioritise flows that move or report money, and let low-risk internal fields wait for normal maintenance.

Is double ever acceptable near money?

For analytics, forecasting or charts that nobody reconciles, double can be fine and much faster. The rule is about values that are stored, transferred, shown to customers or compared with another system; those must be exact.

Why not simply ban float and double everywhere?

Because many services have legitimate floating point uses, such as scores, statistics, geographic coordinates and ratios. A blanket ban would cause noise and workarounds. Rules targeted at monetary names, types and schemas catch the real problem with few false positives.

8Conclusion

In this answer, we saw that Java makes double the easy choice through literals and operators, while BigDecimal needs method calls and rounding decisions. Organisation-wide, we made the right path easy with shared Money and Quantity types and fixed serialisation rules, caught regressions with static analysis and schema linting rolled out from report mode to build-failing, decided rounding and scale once with the domain owners, and tracked reconciliation differences and incidents as metrics to show cost and progress.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by recognising that this is a platform problem, not a people problem. Java makes double the easy choice: a literal like 19.99 is a double, it has operators, and it is what every tutorial uses, while BigDecimal has no literals and every step is a method call with a rounding decision.

Then, if they want more

JSON parsers and JavaScript clients also default to double. So I would change the easy path.

First, a shared library with a Money type and a Quantity type: exact minor units or BigDecimal plus currency or unit, with the common operations and rounding built in, plus Jackson, JPA and OpenAPI support, so that amounts travel as decimal strings or integer minor units with a currency, never as JSON floating numbers.

Second, decide rounding modes, scales and where rounding happens once, with finance and the domain owners, write it down and implement it in the library. Third, automated checks: static rules that flag float or double on fields named like amount, price or balance, schema linting for API specs and review rules for database columns.

I would run them in report mode first to get an inventory, then make them build-failing per team once their findings are fixed. Finally, I would measure: reconciliation mismatches and their total difference, incidents tagged as rounding issues, and findings per team, so leadership sees the cost and we can show the progress.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Engineers keep introducing float and double for monetary and quantity fields across many...": https://scrivio-interview-library.netlify.app/java/types-and-values/e3afdb49d5/