1

I think I'm going a long way around when trying to set an EditText field to a double variable. Here is my method:

    public void setItemCost() {
        EditText x1 = (EditText) findViewById(R.id.itemCost);
        Editable x2 = x1.getText();
        String x3 = x2.toString();
        itemCost = Double.parseDouble(x3);
    }

As a relative noob to Java I'm just wondering if there is a better or more concise way of doing this. Also would I be better using floats for pricing?

Many thanks, Steve

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
Triphead
  • 11
  • 1
  • Re `floats for pricing?`: see [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) – agc Jul 02 '16 at 23:12

1 Answers1

1

No, there is not. Sorry.

However, you can chain it like this

itemCost = Double.parseDouble(x1.getText().toString());

Pongpat
  • 13,248
  • 9
  • 38
  • 51