Decimal separator comma (',') with numberDecimal inputType in EditText
android, android-edittext, decimal-point
Solution
A workaround (until Google fix this bug) is to use an `EditText` with `android:inputType="numberDecimal"` and `android:digits="0123456789.,"`.
Then add a TextChangedListener to the EditText with the following afterTextChanged:
public void afterTextChanged(Editable s) {
double doubleValue = 0;
if (s != null) {
try {
doubleValue = Double.parseDouble(s.toString().replace(',', '.'));
} catch (NumberFormatException e) {
//Error
}
}
//Do something with doubleValue
}
Problem
The `inputType` `numberDecimal` in `EditText` uses the dot `.` as decimal separator. In Europe it's common to use a comma `,` instead. Even though my locale is set as german the decimal separator is still the `.` Is there a way to get the comma as decimal separator?