Reputation: 554
Is there a simple way for the system to return the local currency symbol?
I been searching but I cant find anything, in swift you can achieve this with two lines:
let locale = Locale.current
let currencySymbol = locale.currencySymbol!
¿Is there anything similar in Kotlin?
Upvotes: 0
Views: 2311
Reputation: 617
In case useful, I paste my solution in Kotlin, for currency symbol (i.e. €) and currency code (i.e.: EUR) :
val locale = Locale.getDefault()
val numberFormat = NumberFormat.getCurrencyInstance(locale)
println(numberFormat.currency) // on my device in Italy prints: EUR
val symbol = numberFormat.currency?.symbol
println(symbol) // on my device in Italy prints: €
Upvotes: 1
Reputation: 3224
For Android, it could be an option.
Currency.getInstance(Locale.getDefault()).currencyCode
Upvotes: 0
Reputation: 9211
you can try:
val numberFormat = NumberFormat.getCurrencyInstance(Locale.getDefault())
val symbol = numberFormat.currency?.symbol
// symbol = £
Upvotes: 7