Convert XRP Decimal Strings to Integer Drops Without Floats
Last updated: November 29, 2026
Quick Overview
Write a function that converts a user-supplied XRP amount string such as "12.000345" into an integer number of drops (1 XRP = 1,000,000 drops), rejecting malformed input, negative values, more than six decimal places, and amounts above the total XRP supply. Also write the reverse conversion back to a canonical string.
Ripple
November 29, 20260
0
0 solved
Write a function that converts a user-supplied XRP amount string such as "12.000345" into an integer number of drops (1 XRP = 1,000,000 drops), rejecting malformed input, negative values, more than six decimal places, and amounts above the total XRP supply. Also write the reverse conversion back to a canonical string.
A warm-up in the style of a Ripple phone screen for payments or SDK engineers, mirroring what xrpl.js and xrpl-py do before signing a Payment. The interviewer is checking whether you instinctively avoid binary floating point for money and whether your validation is strict enough that a typo can never move the wrong amount.
What the Interviewer Expects
- State up front that floats are unacceptable and parse the string as integers
- Handle leading dot, trailing zeros, and whole numbers
- Reject more than six significant decimal places rather than silently rounding
- Bound the result by the 100 billion XRP supply
- Provide a round-trip inverse and test it
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 accept scientific notation like 1e-6 safely?
- Should '1.2300000' be accepted or rejected, and why?
- How would you extend this to issued-currency amounts with 15 to 16 significant digits?
- Where in a signing pipeline should this validation live?
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 is a string. Output is a non-negative integer of drops. Valid forms: "7", "0.1", ".5", "12.000345". Trailing zeros past six places are harmless ("1.2300000" is 1.23 XRP), but any non-z...
High-Level Design
Split on the dot into a whole part and a fractional part. Strip trailing zeros from the fraction, check its length is at most 6, right-pad it to six digits, and compute whole * 10^6 + frac. Everythi...