Created
October 9, 2018 17:38
-
-
Save IhwanID/c451a6d0112ce2fbda0e9cb7475389f4 to your computer and use it in GitHub Desktop.
Format Rupiah dengan kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Converter { | |
companion object { | |
fun rupiah(number: Double): String{ | |
val localeID = Locale("in", "ID") | |
val numberFormat = NumberFormat.getCurrencyInstance(localeID) | |
return numberFormat.format(number).toString() | |
} | |
} | |
} |
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
di saya engga work gan. Malah force close appnya