gpt4 book ai didi

java - 如何从 TextView 中获取文本并将其格式化为美元货币?

转载 作者:行者123 更新时间:2023-11-30 01:16:10 24 4
gpt4 key购买 nike

这就是我正在做的 -->

//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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com