为什么计算的结果不符合要求?

gzf30 2004-09-16 09:51:53
mysql数据表中的内容:
用户名 队名 时间 主队 客队 投注额 用户输赢 公司输赢
eileen B 2004-01-23 中国队 法国队 50000.00 2000.00 5000.00
at A 2004-01-01 德国队 中国队 10000.00 1000.00 5000.00
at B 2004-02-05 英国队 巴黎队 20000.00 200.00 500.00
eileen A 2004-01-25 中国队 法国队 30000.00 -500.00 4000.00
计算某个球队的ballrate:
如:德国队\中国队的ballrate:count(用户输赢)/count(投注额),结果应该是1
代码是这样写的,但求出来的结果是NaN, 请帮我看看为什么?
<%
String sql_buamountball="select user_name,home_team_name,away_team_name from bets where play_time>='2004-1-1' and play_time<='2004-1-31' group by home_team_name,away_team_name";
ResultSet rsball=stmt.executeQuery(sql_buamountball);
String ballamount="-1";
String ballamount1="-1";
String sql_bamount;
String ball_name;
String bn1;
String bn2;
String sql_bamount1;
Statement stmt3;
ResultSet rs9;
ResultSet rs10;
float ballrate;
while(rsball.next())
{
out.println("<tr>");
bn1 = rsball.getString("home_team_name");
bn2 = rsball.getString("away_team_name");
ball_name = bn1 + "/" + bn2;
out.println("<td>" + rsball.getString("user_name") + "</td>");
out.println("<td>");
out.println(rsball.getString("home_team_name") + "/" + rsball.getString("away_team_name"));
out.println("</td>");
stmt3=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
sql_bamount="select count(user_amount) as qa from bets where user_amount>0 and user_name='"+ball_name+"'";
rs10=stmt3.executeQuery(sql_bamount);
if(rs10.next())
ballamount=rs10.getString("qa");
rs10.close();
sql_bamount1="select count(amount) as qa1 from bets where user_name='"+ball_name+"'";
rs9=stmt3.executeQuery(sql_bamount1);
if(rs9.next())
ballamount1=rs9.getString("qa1");
rs9.close();
ballrate=(float)Integer.parseInt(ballamount)/(float)Integer.parseInt(ballamount1);
out.println("<td>");
out.println(ballrate);
out.println("</td>");
stmt3.close();
}
rsball.close();
%>


...全文
54 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
如果被0除的话结果就可能是NaN
回复
ecaol 2004-09-16
up
回复
opencsdn 2004-09-16
Integer.parseInt(ballamount1)是不是0啊,
还有ballrate:count(用户输赢)/count(投注额),结果应该是1?????应该是(0.1)吧,然后来个parseInt(),就是0了

回复
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-16 09:51
社区公告
暂无公告