title: How to display Double value on edittext- android
body: <p>I am creating an application which takes numerical vales from the edittext, does calculation on them like calculation of discount, change of currency etc and then display them on another edittext.</p>
  
  <p>I am converting values from string to Double and then again displaying it in the screen by converting double to string. I have marked the line where calculation and displaying of values takes place.</p>
  
  <p>My problem is that, nothing is displayed on the edittext and no error is generated in the logcat.</p>
  
  <pre><code>public class Calculator extends Activity implements View.OnClickListener {
  
      EditText carat,list,price,total,discount,converter,discamt,caratrs;
      Button submit;
      Button one, two, three, four, five, six, seven, eight, nine, zero, clear,dot,calc;
      double int_list=0,int_carat=0,int_discount=0,int_converter=0,int_price=0,int_total=0,int_discamt=0,int_pricers=0;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_calculator);
  
         carat=(EditText)findViewById(R.id.carat);
          list=(EditText)findViewById(R.id.list);
          price=(EditText)findViewById(R.id.price);
          total=(EditText)findViewById(R.id.total);
          discount=(EditText)findViewById(R.id.discount);
          converter=(EditText)findViewById(R.id.converter);
          discamt=(EditText)findViewById(R.id.discamt);
          caratrs=(EditText)findViewById(R.id.caratrs);
  
          submit=(Button)findViewById(R.id.submit);
          calc=(Button)findViewById(R.id.calculate);
  
          one = (Button) findViewById(R.id.one);
          two = (Button) findViewById(R.id.two);
          three = (Button) findViewById(R.id.three);
          four = (Button) findViewById(R.id.four);
          five = (Button) findViewById(R.id.five);
          six = (Button) findViewById(R.id.six);
          seven = (Button) findViewById(R.id.seven);
          eight = (Button) findViewById(R.id.eight);
          nine = (Button) findViewById(R.id.nine);
          zero = (Button) findViewById(R.id.zero);
          clear=(Button)findViewById(R.id.clear);
          dot=(Button)findViewById(R.id.dot);
  
  
  
          price.setInputType(InputType.TYPE_NULL);
          total.setInputType(InputType.TYPE_NULL);
          carat.setInputType(InputType.TYPE_NULL);
          list.setInputType(InputType.TYPE_NULL);
          converter.setInputType(InputType.TYPE_NULL);
          discount.setInputType(InputType.TYPE_NULL);
          discamt.setInputType(InputType.TYPE_NULL);
          caratrs.setInputType(InputType.TYPE_NULL);
  
          try{
              one.setOnClickListener(this);
  
              two.setOnClickListener(this);
  
              three.setOnClickListener(this);
  
              four.setOnClickListener(this);
  
              five.setOnClickListener(this);
  
              six.setOnClickListener(this);
  
              seven.setOnClickListener(this);
  
              eight.setOnClickListener(this);
  
              nine.setOnClickListener(this);
  
              zero.setOnClickListener(this);
  
  
              dot.setOnClickListener(this);
  
          }
          catch(Exception e){
  
          }
  
  
          clear.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if(carat.isFocused())
                  {
                      carat.setText("");
                  }
                  else if(price.isFocused())
                  {
                      price.setText("");
                  }
                  else if(total.isFocused())
                  {
                      total.setText("");
                  }
                  else if(list.isFocused())
                  {
                      list.setText("");
                  }
                  else if(discount.isFocused())
                  {
                      discount.setText("");
                  }
                  else if(converter.isFocused())
                  {
                      converter.setText("");
                  }
                  else if(discamt.isFocused())
                  {
                      discamt.setText("");
                  }
                  else if(caratrs.isFocused())
                  {
                      caratrs.setText("");
                  }
              }
          });
  
  ---------------------------This is where all the calculation takes place including displaying the value on the edittext-----------------------------
  
  
  
      calc.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              try {
                  int_list = Double.parseDouble(list.getText().toString());
                  int_carat = Double.parseDouble(carat.getText().toString());
                  int_discount = Double.parseDouble(discount.getText().toString());
                  int_converter = Double.parseDouble(converter.getText().toString());
                  int_discamt = Double.parseDouble(discamt.getText().toString());
  
  
                  int_discamt = (int_list * int_discount) / 100;
                  int_price = int_list - int_discamt;
                  int_pricers = int_price * int_converter;
                  int_total = int_price * int_converter * int_carat;
  
  
                  price.setText(Double.toString(int_price));
                  discamt.setText(Double.toString(int_discamt));
                  caratrs.setText(Double.toString(int_pricers));
                  total.setText(Double.toString(int_total));
              }
              catch(NumberFormatException e)
              {
                  e.printStackTrace();
              }
  
          }
      });
  
       }
  
  
      @Override
      public void onClick(View v) {
  
  
  
          if(carat.isFocused())
          {
              carat.setText(carat.getText().toString() + ((Button) v).getText());
          }
  
          else if(list.isFocused())
          {
              list.setText(list.getText().toString() +((Button)v).getText());
          }
           else if(discount.isFocused())
          {
              discount.setText(discount.getText().toString() +((Button)v).getText());
          }
          else if(converter.isFocused())
          {
              converter.setText(converter.getText().toString() +((Button)v).getText());
          }
  
  
      }
  
  }
  </code></pre>
  
  <p>This is what i am getting in logcat</p>
  
  <pre><code>05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ java.lang.NumberFormatException: Invalid double: ""
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at java.lang.StringToReal.invalidReal(StringToReal.java:63)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at java.lang.StringToReal.parseDouble(StringToReal.java:248)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at java.lang.Double.parseDouble(Double.java:295)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at com.diamond.traders.Calculator$2.onClick(Calculator.java:176)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at android.view.View.performClick(View.java:4438)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at android.view.View$PerformClick.run(View.java:18422)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:733)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5017)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  05-07 18:00:14.918  14299-14299/com.diamond.traders W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  </code></pre>