【发布时间】:2012-03-11 14:41:07
【问题描述】:
当我将整数相乘时,我有以下代码,但是当我尝试将十进制数相乘并将答案显示为十进制数时出现错误
public void actionPerformed(ActionEvent e) {
int num1=Integer.parseInt(textArea_price.getText());
int num2=Integer.parseInt(textArea_quantity.getText());
int result = num1*num2;
textField_Name.setText(Integer.toString(result));
感谢任何关于我可以更改或添加以使此代码与十进制数字一起使用的建议。
【问题讨论】:
-
请说明你看到了什么错误,在哪一行。
-
(“整数”与“小数”是什么意思?)
-
你知道,parseInt() 只能解析int,对吧?
-
我收到的错误消息是 14:44.56 78[dbg] CShellExt::CShellException in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "12.34"跨度>
-
@HotLicks 他可能想解析浮点数..