Skip to content

Instantly share code, notes, and snippets.

@Popalay
Created July 23, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Popalay/304ee99dd9bc4f3496673fc1b86ba782 to your computer and use it in GitHub Desktop.
Save Popalay/304ee99dd9bc4f3496673fc1b86ba782 to your computer and use it in GitHub Desktop.
Set limit of digits after decimal point
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
}
@Popalay
Copy link
Author

Popalay commented Jul 23, 2019

EditText.filters = arrayOf(DecimalDigitsInputFilter(decimalDigits = 2))

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