Convert Amounts Between Currencies With Different Minor Units
Last updated: November 29, 2026
Quick Overview
Write a function that converts an integer amount in a source currency's minor units (cents, yen, fils) into the destination currency's minor units at a given rate, rounding correctly. Currencies have 0, 2 or 3 decimal places.
Airwallex
November 29, 20260
0
0 solved
Write a function that converts an integer amount in a source currency's minor units (cents, yen, fils) into the destination currency's minor units at a given rate, rounding correctly. Currencies have 0, 2 or 3 decimal places.
A warm-up in the style of an Airwallex backend phone screen, since every conversion on a multi-currency Global Account has to land on an exact integer balance. The interviewer is checking whether you avoid floats for money, know that JPY and KWD do not have two decimals, and can state a rounding policy.
What the Interviewer Expects
- Represents money as integers in minor units, never binary floats
- Uses a decimal type for the rate multiplication
- Looks up decimal places per currency instead of assuming 2
- Chooses and justifies a rounding mode (half-even or half-up)
- Rejects unknown currencies explicitly
- Tests a tie case and a zero-decimal currency
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you make sure the sum of many converted line items equals the converted total?
- Where does the FX markup get applied, and does it change your rounding?
- How would you handle a rate quoted with 8 significant digits?
- What changes if regulators in one market mandate half-up rounding?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: amount_minor (int) in the source currency, source and destination ISO codes, and the rate as a string (destination per one source). Output: int in destination minor units. Currencies carry 0 ...
High-Level Design
- Shift the integer to a major-unit
Decimalusing the source exponent. - Multiply by
Decimal(rate)built from the string, so no float error sneaks in. - Quantize to the destination exponent wit...