Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Created October 9, 2018 17:38
Show Gist options
  • Save IhwanID/c451a6d0112ce2fbda0e9cb7475389f4 to your computer and use it in GitHub Desktop.
Save IhwanID/c451a6d0112ce2fbda0e9cb7475389f4 to your computer and use it in GitHub Desktop.
Format Rupiah dengan kotlin
class Converter {
companion object {
fun rupiah(number: Double): String{
val localeID = Locale("in", "ID")
val numberFormat = NumberFormat.getCurrencyInstance(localeID)
return numberFormat.format(number).toString()
}
}
}
@muhfara
Copy link

muhfara commented Apr 13, 2021

di saya engga work gan. Malah force close appnya

@okomtayiw
Copy link

fun String.toCurrencyFormat(): String {
val localeID = Locale("in", "ID")
val doubleValue = this.toDoubleOrNull() ?: return this
val numberFormat = NumberFormat.getCurrencyInstance(localeID)
numberFormat.minimumFractionDigits = 0
return numberFormat.format(doubleValue)
}

ini disaya work gan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment