Convert Between Dollars and Euros to the Cent
Updated
Problem statement
amount is a money amount written with exactly two decimals, such as "250.00". rate is how many units of the other currency one unit buys, written with one to six decimals, such as "0.91537". The same function converts dollars to euros or euros to dollars; only the rate differs.
Return amount × rate rounded to the nearest cent, where an exact half cent rounds up. Write the result with exactly two decimals and no extra leading zeros, for example "228.84" or "0.00".
Function
convertCurrency(amount: String, rate: String) → StringExamples
Example 1
amount = "250.00"rate = "0.91537"return = "228.84"250.00 × 0.91537 = 228.8425. The digit after the cents is 2, so the amount rounds down to 228.84.
Example 2
amount = "1.15"rate = "1.5"return = "1.73"1.15 × 1.5 = 1.725, exactly halfway between 1.72 and 1.73. Halves round up, so the answer is 1.73. Floating-point multiplication gets 1.7249999… here and would round the wrong way.
Example 3
amount = "0.01"rate = "0.4"return = "0.00"0.01 × 0.4 = 0.004, less than half a cent, so it rounds to 0.00. The answer still shows two decimals.
Constraints
amountmatchesdigits.ddwith no leading zero before other digits, and0.01 <= amount <= 10000000.00.ratehas a whole part, a dot and 1 to 6 decimals, with no leading zero before other digits, and0.000001 <= rate <= 100.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Convert Hexadecimal to Dotted IPv4Microsoft · ONSITE INTERVIEWMicrosoft interview questions
- Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
- Caesar Cipher with a Precomputed AlphabetAmazon · ONSITE INTERVIEW
- Add Two Binary StringsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Substrings Made Only of VowelsExpedia · ONSITE INTERVIEWExpedia interview questions
- Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
- Iterate Canonical IPv6 AddressesOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Nth Staged License PlateGoogle · ONSITE INTERVIEWGoogle interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences