Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从文本视图中获取文本并将其格式化为美元货币?_Java_Android_Textview_Currency_Number Formatting - Fatal编程技术网

Java 如何从文本视图中获取文本并将其格式化为美元货币?

Java 如何从文本视图中获取文本并将其格式化为美元货币?,java,android,textview,currency,number-formatting,Java,Android,Textview,Currency,Number Formatting,这就是我正在做的--> 文本视图中的结果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);

这就是我正在做的-->

文本视图中的结果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 ));
您好,您可以使用此选项(Locale.US将数字格式化为美国标准,%.2f表示十进制数字):


String.format(Locale.US,“%.2f”,doubleValue)

我很高兴它能帮上忙。欢迎:)我有一个更复杂的问题,我不知道如何问它。如果你想聊天,你可以来聊天。当然,我有用户代码,你可以再看十遍。然后用户按下一个按钮并进行计算。从中打印小计和总计。当用户第一次在编辑文本中输入数字时,按下按钮,然后向上滚动到输入的数字,然后再次按下计算按钮应用程序“停止工作”您将需要共享日志,然后我可以说出发生了什么事情@Casey:D!
/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 ));