java无法将字符串转换为Int进行求和
我在Android Studio中有以下代码
public void addTotal() {
String sub1 = subtotal1.getText().toString();
String newSub1 = sub1.replace("$", "");
String sub2 = subtotal2.getText().toString();
String newSub2 = sub2.replace("$", "");
String sub3 = subtotal3.getText().toString();
String newSub3 = sub3.replace("$", "");
totalAmt.setText(newSub1 + newSub2 + newSub3);
}
我无法将它们作为整数相加。我错过什么了吗
subtotal1
、subtotal2
、subtotal3
在应用程序中TextView
# 1 楼答案
假设您的文本美元金额可能有一个小数部分,您可以在此处使用
Double#parseDouble
: