2017-03-06 13 views
0

私は結果をダブルとして表示するが、intとして表示したいのですか?これは私のすでに動作するコードです結果をintとしてテキスト表示で表示する

Bundle b = getIntent().getExtras(); 
double result = b.getDouble("total"); 

TextView display = (TextView)findViewById(R.id.txtResult); 
display.setText(+result+ "well done"); 

答えて

0

その結果は、整数になるように、二重を強制的に小数部分を失っている、二重の原始的である場合は、それをキャストすることができます....

display.setText((int)result+ "well done"); 

結果は二重のラッパーである場合には、ダブル#intValue(メソッドを呼び出す)

display.setText(result.intValue()+ "well done"); 
+0

完璧な、ありがとう君は! – gw95

+0

あなたはようこそ... –

-1

あなたは以下のようにテキストを設定する必要があります。

0

1あなたがしたいですか:整数にダブル変換ではありません
1ダブル整数

1-
4-doubleをintに
3-doubleをintに
2ダブルを整数に可能です。あなたは倍増するダブルを変換する必要があり、その後、

Double D= Double.valueOf(5.0); 
double d= D.doubleValue(); 
int i=(int)d; 
Integer I= Integer.valueOf(i); 

あなたが進行ライン2と、このような3缶整数にint型とエンド変換int型にするために、二重変換:int型へのダブル

int i= D.intValue(); 

2-

Double D= Double.valueOf(5.0); 
int i= D.intValue(); 

、3- intへのダブル:

double d; 
int i=(int)d 

あなたがライン2のためのラウンドに使用できるaslo:

int i=Math.round(d); 

、4-ダブル整数へ

再び
double d; 
int i=(int)d 
Integer I= Integer.valueOf(i); 

あなたが行2のラウンドに使用することができます働い

int i=Math.round(d); 
関連する問題