Convert Human Coin Amounts to Base Units Without Floats

Last updated: November 29, 2026

Quick Overview

Write functions that convert a user-entered decimal string such as "0.1" into integer base units (satoshis, wei, lamports) for a coin with a given number of decimals, and back again, rejecting malformed input and amounts with more precision than the coin supports.

BitGo
Coding & Algorithms
Software Engineer
BitGo
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Write functions that convert a user-entered decimal string such as "0.1" into integer base units (satoshis, wei, lamports) for a coin with a given number of decimals, and back again, rejecting malformed input and amounts with more precision than the coin supports.

BitGo supports hundreds of coins and tokens with different decimal places (8 for BTC, 18 for ETH, 6 for many stablecoins), and every send request passes through amount parsing. A phone screen uses this to check whether a candidate knows why floating point is unacceptable for money and can write careful string handling.

What the Interviewer Expects
  • Refuses to use float at any step and explains why 0.1 cannot be represented exactly
  • Handles missing whole part, missing fraction, signs and trailing zeros
  • Rejects extra precision that would silently truncate value instead of rounding
  • Formats back without trailing zeros and with correct zero padding
  • Mentions that decimals come from per-coin config, not hard-coded constants
Key Topics to Cover
integer arithmetic
string parsing
decimal precision
input validation
multi-coin support
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle tokens whose decimals are only known after reading the contract?
  • Should 1.500 with 2 decimals be accepted, and why?
  • How does this change when the API accepts amounts as JSON numbers instead of strings?
  • Where else in a wallet backend do float bugs usually hide?
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Requirements

Input: a decimal string and the coin's decimals. Output: an exact integer number of base units. Reverse: integer to a canonical display string. Reject empty strings, multiple dots, non-digits, and a...

High-Level Design

Treat the amount as text. Split on the dot into whole and fractional parts, validate both are digits, right-pad the fraction to decimals and combine as whole * 10**decimals + frac. Python ints are...


Submit Your Answer
Markdown supported

Related Questions