October 2021
Intermediate to advanced
500 pages
16h 23m
English
So far, so good. But it would be nicer if Doubloons4Gold used currency formatting, so your output looked like this:
Hello from Kotlin/JVM!
The current exchange rate is $1.38 per doubloon
How many doubloons do you want?
50
50.0 doubloons will cost you $69.04
You want this formatting to apply across all platforms your application supports, so it belongs in your common codebase. Create a new file in commonMain/kotlin called Currency.kt and define an extension function on Double called formatAsCurrency.
As the name suggests, this function will convert a double to an appropriately formatted string for the user’s local currency. But for now, leave the implementation as a to-do. We will explain how to implement it shortly. ...
Read now
Unlock full access