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.
currency_convert(amount_minor: int, rate_bps: int) → int
Where you start
def currency_convert(amount_minor: int, rate_bps: int) -> int:
Worked examples
| Call | Result |
|---|---|
currency_convert(1000, 8000) | 800 |
currency_convert(500, 10000) | 500 |
currency_convert(1250, 3333) | 416 |
currency_convert(0, 5000) | 0 |
Hint
Multiply then divide by 10000, rounding down.
Reference solution in Python
def currency_convert(amount_minor: int, rate_bps: int) -> int:
return amount_minor * rate_bps // 10000