问题描述
public void comAccount(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {String b = req.getParameter("balance");NewCustomer customer = new NewCustomer();DAOFactory daoFactory = DAOFactory.getDAOFactory(DAOFactory.ORACLE);NewCustomerDAO newcustomerDao = daoFactory.getCustomerDAO();newcustomerDao.heZhangJiSuan(customer);String a = customer.getBalance();System.out.println("a=="+a);java.util.Vector error = new java.util.Vector();int x,y;x = Integer.parseInt(b); //程序执行到这里报异常//java.lang.NumberFormatException: For input string: "200.00"y = Integer.parseInt(a);if( x>y ){int c = x - y;error.add("已扣除费用"+c+"RMB");req.setAttribute("errorss", error);}else{error.add("账户余额不足,请充值!");req.setAttribute("errors", error);}String address = "/page/comAccount.jsp";req.getRequestDispatcher(address).forward(req, resp);}
解决方案
不能这样用,如果确定这里输入的都是整数,那么可以先用Double.parseDouble(String string)方法来转成double类型下面代码测试通过String s="200.00";int i=(int)Double.parseDouble(s);System.out.println(i);如果数据可能不是整数,建议修改程序的其它部分
解决方案二:
金额信息一般都是Double类型 建议直接将int改为Double,然后包装类方法也跟着一起换成Double.parseDouble()