Drill

ProblemsGo › finance

Convert between currencies

easyfinanceMathGo

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

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.

Solve it in Python →

Where you start

func currencyConvert(amountMinor int, rateBps int) int {
	
}

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 Go
func currencyConvert(amountMinor int, rateBps int) int {
	return amountMinor * rateBps / 10000
}

The same problem in another language

More finance problems in Go