Convert between currencies
A money-changer converts an amount in minor units at a rate quoted in basis points (per ten thousand).
- The result is floor(amount × rate / 10000), staying in minor units.
- Basis points are tenths of a percent: 10000 bps means the rate is exactly 1.
- A zero amount or zero rate converts to zero.
currencyConvert(amountMinor: int, rateBps: int) → int
Go 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.
Where you start
func currencyConvert(amountMinor int, rateBps int) int {
}
Worked examples
| Call | Result |
|---|---|
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 Go
func currencyConvert(amountMinor int, rateBps int) int {
return amountMinor * rateBps / 10000
}