我正在尝试从editText和textView中获取一个值,并将其添加在一起并显示它。当我尝试执行此操作时,出现错误:
java.lang.NumberFormatException: For input string:
但是,当我单独进行操作时,它可以工作,问题出在我添加时。抱歉,无法进行硬编码。
if (position == 1 && editTextBillAmount.getText().toString().length() > 0) {
textViewMeal.setText(df.format(Double.parseDouble(editTextBillAmount.getText().toString())));
textViewTipAmount.setText(df.format(Double.parseDouble(editTextBillAmount.getText().toString()) * .10));
textViewFull.setText(df.format(Double.parseDouble(editTextBillAmount.getText().toString()+df.format(Double.parseDouble(editTextBillAmount.getText().toString()) * .10))));
Toast.makeText(MainActivity.this, "10%", Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:0)
我想您正在将.10乘以一个字符串,从而导致了该错误。如果您在另一个变量中进行计算,然后将其放入结果中,则会解决好问题。希望它能解决。让我知道它可以工作,否则我将分享修改后的代码。
答案 1 :(得分:0)
如果不需要Double格式,则可以使用以下格式:
:has()
如果Double需要使用格式,请检查editTextBillAmount中的字符串格式是否正确