Original project: https://github.com/yigitserin/CurrencyEditText
CurrencyEditText is an EditText library for inputting currency values. It supports grouping and decimal seperators.
- yigitserin/CurrencyEditText#1
- No currency symbol support
Copy CurrencyEditText to your project. Gradle dependency comming soon.
val currencyEt = findViewById<CurrencyEditText>(R.id.currency_et)
currencyEt.setLocale(Locale("en","US")) //Default Locale.getDefault()
currencyEt.setDigitsBeforeZero(10) //Default Int.MAX_VALUE
currencyEt.setDigitsAfterZero(4) // Default 2
currencyEt.inputType = InputType.TYPE_CLASS_PHONE //Default InputType.TYPE_CLASS_PHONE
//Extra: Get Double number
val doubleNumber = findViewById<TextView>(R.id.double_tv)
currencyEt.addNumericValueChangedListener(object : CurrencyEditText.NumericValueWatcher{
override fun onChanged(newValue: Double) {
//Readable Double without rounding or abbreviations
doubleNumber.text = DecimalFormat("#.###############").format(newValue)
}
override fun onCleared() {
doubleNumber.text = ""
}
} )
<[package].CurrencyEditText
android:id="@+id/currency_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:digitsBeforeZero="10"
app:digitsAfterZero="4"/>