Drill

ProblemsJava › finance

Convert between currencies

easyfinanceMathJava

A money-changer converts an amount in minor units at a rate quoted in basis points (per ten thousand).

currencyConvert(amountMinor: int, rateBps: int) → int

Java needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

int currencyConvert(int amountMinor, int rateBps) {
    
}

Worked examples

CallResult
currencyConvert(1000, 8000)800
currencyConvert(500, 10000)500
currencyConvert(1250, 3333)416
currencyConvert(0, 5000)0

Hint

Multiply then divide by 10000, rounding down.

Reference solution in Java
int currencyConvert(int amountMinor, int rateBps) {
    return (amountMinor * rateBps) / 10000;
}

The same problem in another language

More finance problems in Java