assignmentEndScore = resultSet.getDouble("AssignmentEndScore");这样试试DecimalFormat form = new DecimalFormat("0.00");
String num=form.format(rs.getDouble("num"));
这里的0.00就是小数点的位置计算,可以决定取得的String num是保留小数点后多少位数。

解决方案 »

  1.   

    float 和 double 本来就不是精确保存的,难
      

  2.   

    DecimalFormat 这个是那个包里的啊?
      

  3.   

    assignmentEndScore = resultSet.getDouble("AssignmentEndScore");这个就是数据库里面有多少取多少的。注意,这里和你原来的区别,getFloat != getDouble
      

  4.   

    <%@ page contentType = "text/html; charset=gb2312" import="java.text.*,java.util.*,java.net.*"%>
      

  5.   

    不可以用getDouble吧,我的数据库里类型是float啊
      

  6.   

    float就是双精度吧。我这个是程序已经通过的了。
    我的数据库中对price的设置就是float型,而且我这里使用的是select avg(price) as num from car_price,得到的结果也是float型的。用Double一定是可以读取的。
      

  7.   

    我用的是sql server数据库,但是我认为这个应该和什么牌子的数据库没有关系吧。我这里是可以通过的
    Statement stmt8 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ResultSet rs9=stmt8.executeQuery("select avg(price_1) as num1 from car_price where model_id="+id3);
    if(rs9.next()) {
    DecimalFormat form = new DecimalFormat("0.00");
    String num1=form.format(rs9.getDouble("num1"));
    String num1_1="null";
    if("0.00".equals(num1)) {
    num1_1="---";
    } else {
    num1_1=num1;
    }
    %>
                      <td width="117"><div align="center"><font color=#000066><%=num1_1%>万元</font></div></td>
    <%
    }
    rs9.close();
    stmt8.close();上面是我在一个现在运行的汽车网站的程序片段。其中price_1字段在数据库中就是float类型