Format money
A JavaScript exercise from Scriptdrill. Solve it with a code editor in your browser that runs your function against example and hidden tests, and it is checked the moment you submit.
The task
Format `amount` as money in the given ISO currency code (like `"USD"` or `"JPY"`) and locale, the way `Intl.NumberFormat` does with `style: "currency"`. Each currency keeps its usual number of decimals, and each locale its own grouping.
What this exercise teaches
Intl.NumberFormat knows each currency's minor units (2 for USD, 0 for JPY) and each locale's grouping, such as the Indian lakh grouping 12,34,567. Hand-built formatting gets these wrong.
A hint if you get stuck
Look at `Intl.NumberFormat` with the `style: "currency"` option. It handles the symbol, the sign, grouping and rounding for you.
This exercise is part of Pro
Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.
You create a free account first, so Pro is attached to it.
Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.