2016-06-15 2 views
1

これは私がやっているものです - TextViewの中>テキストをTextViewから取得して米ドル通貨でフォーマットするにはどうすればよいですか?

//get entered texts from the edittexts,and convert to integers. 
Integer value1 = Integer.parseInt(sand1.getText().toString()); 


//doing a calculation 
Double calculatedValue1 = (9.5*value1); 


//set the value to the textview, to display on screen. 
result1.setText("$"+ calculatedValue1.toString()); 

結果1は次のようになります。##.#

私はこのような何かにあなたのコードを変更し$##.##

答えて

1

のように見えるためにそれを必要とします:

/get entered texts from the edittexts,and convert to integers. 
Integer value1 = Integer.parseInt(sand1.getText().toString()); 


//doing a calculation 
Double calculatedValue1 = (9.5*value1); 


//set the value to the textview, to display on screen. 
result1.setText("$"+ String.format("%.2f", calculatedValue1)); 
+0

感謝。 – Casey

+0

私はそれが助けてうれしいです。ようこそ –

+0

ありがとうありがとう – Casey

0

こんにちは、これは、Locale.USを米国標準としてフォーマットし、%.2fを10進数):勤務

String.format(Locale.US, "%.2f", doubleValue);

+0

おかげでよかったよ – Casey

+0

恐ろしい@Casey:D! – AmirG