title: Decimal Places using double with toString, android
body: <p>I am creating a simple program that performs simple math functions on the values a user enters in the EditText views. The first two EditText views contain integers and the last could be a decimal, thus the answer could also need to be in decimal form so I set the and (vis) as a double, but how can I limit the decimal places to four? Everything is running fine, the answer is just many decimal places long!</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void onClick(View v) {
              String a,b,t;
              double vis;
  
              EditText txtbox1 = (EditText)findViewById(R.id.A);
                  EditText txtbox2 = (EditText)findViewById(R.id.B);
                  EditText txtbox3 = (EditText)findViewById(R.id.t);
                  TextView tv = (TextView) findViewById(R.id.Answer);
  
              a = txtbox1.getText().toString();
              b = txtbox2.getText().toString();
              t = txtbox3.getText().toString();
  
              vis = ((Integer.parseInt(a)*1) + (Integer.parseInt(b)*2)) /       (Double.parseDouble(t));
              tv.setText(double.toString(vis));       
      }
  }
  </code></pre>
  
  <p>Thanks so much!</p>