日期:2014-05-17  浏览次数:21167 次

做除法运算,用ASP代码怎么写?
我在做一个班级学生成绩统计表,其中有一栏是求学科成绩合格率的,我知道是用两个语句查到合格和全部人数,用合格人数除以全部人数得出的结果就是合格率,但就是相除这里我不会做,还有就是怎么把结果显示出来,要求用百分比的形式显示出来,且百分号前的数字只能是个位数或十位数或百位数(如:45%或6%或100%),我是用ACCESS做的,只有一个数据表,表名是scores,下面是我用的两个查询语句:
<%    
dim   rshgr1        
dim   sqlhgr1

set   rshgr1=server.createobject( "adodb.recordset ")
sqlhgr1= "select   count(id)   as   hgrs1   from   scores   where   language> =60       and   grade= "&grade& "   and   class= "&banji& " "                     '查询语文成绩合格人数
on   error   resume   next  
rshgr1.Open   sqlhgr1,conn,1      
%>


<%  
dim   rshgl1    
dim   sqlhgl1


set   rshgl1=server.createobject( "adodb.recordset ")
sqlhgl1= "select   count(*)   as   zrsh   from   scores   where     grade= "&grade& "   and   class= "&banji& " "       '查询总人数
on   error   resume   next  
rshgl1.Open   sqlhgl1,conn,1
%>
 
请各位大侠帮忙,能给出这一块ASP代码?急!!!!谢!!!!!!!!!!




------解决方案--------------------
合格率=合格人数/全部人数 '除法运算
合格率=left(合格率,3)
合格率=合格率*100& "% "



------解决方案--------------------
<%
dim rshgr1
dim sqlhgr1
dim count_hgr

set rshgr1=server.createobject( "adodb.recordset ")
sqlhgr1= "select count(id) as hgrs1 from scores where language> =60 and grade= "&grade& " and class= "&banji& " " '查询语文成绩合格人数
on error resume next
rshgr1.Open sqlhgr1,conn,1
count_hgr=rs( "hgrs1 ")
%>


<%
dim rshgl1
dim sqlhgl1
dim count_sum


set rshgl1=server.createobject( "adodb.recordset ")
sqlhgl1= "select count(*) as zrsh from scores where grade= "&grade& " and class= "&banji& " " '查询总人数
on error resume next
rshgl1.Open sqlhgl1,conn,1
count_sum=rs( "zrsh ")
%>

<%
dim rate
rate=count_hgr/count_sum
rate=rate*100
rate=left(rate,instr(rate, ". ")-1)
rate=rate& "% "
response.write rate
%>
------解决方案--------------------
melodywithme()
rate=left(rate,instr(rate, ". ")-1)

这样才对..
我用left那样没考虑到除后的结果会不会大于100....
------解决方案--------------------
<%
dim rs,jige,renshu,sqlhgr1
on error resume next
set rs=server.createobject( "adodb.recordset ")
sqlhgr1= "select count(id) as hgrs1 from scores where language> =60 and grade= "&grade& " and class= "&banji& " " '查询语文成绩合格人数
rs.Open sqlhgr1,conn,1,1
jige=rs( "hgrs1 ")
rs.close
sqlhgl1= "select count(*) as zrsh from scores where grade= "&grade& " and class= "&banji& " " '查询总人数
rs.Open sqlhgl1,conn,1,1
renshu=rs( "zrsh ")
rs.close
set rs=nothing
Response.Write( "及格率为: "&FormatPercent(Cint(jige)/Cint(