Created
July 23, 2019 10:06
-
-
Save Popalay/304ee99dd9bc4f3496673fc1b86ba782 to your computer and use it in GitHub Desktop.
Set limit of digits after decimal point
This file contains hidden or 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 DecimalDigitsInputFilter(val decimalDigits: Int) : InputFilter { | |
override fun filter(source: CharSequence, start: Int, end: Int, dest: Spanned, dstart: Int, dend: Int): CharSequence? = | |
if (dstart > dest.indexOf('.') && | |
dest.toString().substringAfter('.', "").length > decimalDigits - 1 | |
) "" else null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
EditText.filters = arrayOf(DecimalDigitsInputFilter(decimalDigits = 2))