0

I have an EditText-window which when I type a double number for example 0,01 displays 001), it will not take the period (comma) sign (oper2 representing operand2). What is strange is that the EditText window over it (oper1 representing operand2) takes period. As far as I can see it has exactly the same code. Can anyone tell me what is wrong? Here is the relevant java code:

if ((operand1.getText().length() > 0) && (operand2.getText().length() > 0)) {
                double oper1 = Double.parseDouble(operand1.getText().toString());
                double oper2 = Double.parseDouble(operand2.getText().toString());
                double theResult = ((oper2 * oper1 * 60) / 40);
                String stringResult = String.format("%.2f", theResult);
                mlHour.setText(stringResult + " ml/t");
            } else {
                Toast.makeText(AdrenalinActivity.this, getString(R.string.toastNoradrenalin), Toast.LENGTH_LONG).show();
            }
        }
    });
user820913
  • 623
  • 4
  • 12
  • 23
  • How are you defining your EditText? – Doug Stevenson Mar 05 '16 at 20:27
  • You led me in the right direction. I went in to the properties for the EditText window and checked "Number Decimal" which for some reason wasn´t checked. This solved the problem. Thank you! – user820913 Mar 05 '16 at 20:34
  • Your layout? What properties are being set on the TextView? – Doug Stevenson Mar 05 '16 at 20:36
  • Possible duplicate of [Decimal separator comma (',') with numberDecimal inputType in EditText](http://stackoverflow.com/questions/3821539/decimal-separator-comma-with-numberdecimal-inputtype-in-edittext) – Doug Stevenson Mar 05 '16 at 20:44

1 Answers1

3

In the XML for the EditText, if you have android:inputType="number" that would only allow numerics, I believe.

If so change to android:inputType="numberDecimal"

You may also want to compliment this with android:digits="0123456789." (this limits the input to only use those digits (eg comma, - (negative) would not be able to be typed).

MikeT
  • 51,415
  • 16
  • 49
  • 68