Drill

ProblemsTypeScript › finance

Convert between currencies

easyfinanceTypeScript

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

Solve it in the editor →

Where you start

function currencyConvert(amountMinor: number, rateBps: number): number {
  
}

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 TypeScript
function currencyConvert(amountMinor: number, rateBps: number): number {
  return Math.floor((amountMinor * rateBps) / 10000);
}

The same problem in another language

More finance problems in TypeScript