这就是我正在做的 -->
//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());
TextView 中的结果 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 ));
关于java - 如何从 TextView 中获取文本并将其格式化为美元货币?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37844405/