2016-04-06 16 views
0

String.ValueOfを最も近い整数に丸めようとしています。 String.valueOf(result)を最も近い整数にする方法。丸めString.ValueOfを最も近い整数に

public void onClick(View v) { 
     double result =0; 
     double result1 =0; 
     double a = Double.parseDouble(weightEntered.getText().toString().trim()); 
     double b = 2.2; 
    if(v == button_convert) 
    { 
     if(lbs_kg.isChecked() == true) { 
      result = (a/b); 
      String str = String.valueOf(result); 
      t1.setText(str); 
     } 
+2

恐らくMath.round(String.valueOf(結果は))行う必要があります:) –

+0

を第二のそれについて考えてみて@SandeepBhandari。 –

+0

ここに解決方法があります:http://stackoverflow.com/questions/2808535/round-a-double-to-2-decimal-places – Pooya

答えて

2
String str = String.valueOf(Math.round(result)); 
+0

これは素晴らしい仕事をありがとう – Ryan159

関連する問題