String str=request.getParameter("input1");
24: float f=0;
25: try{
26: f=Float.parseFloat(str);//Double.parseDouble(str)也有问题
27: }
28: catch(NumberFormatException e){
29: out.print("error!");
总是有这个问题,而我定义
String str=request.getParameter("input1");
24: float f=0;
25: try{
26: f=Integer.parseInt(str);
27: }
28: catch(NumberFormatException e){
29: out.print("error!");
就没有问题,请问是什么原因?
24: float f=0;
25: try{
26: f=Float.parseFloat(str);//Double.parseDouble(str)也有问题
27: }
28: catch(NumberFormatException e){
29: out.print("error!");
总是有这个问题,而我定义
String str=request.getParameter("input1");
24: float f=0;
25: try{
26: f=Integer.parseInt(str);
27: }
28: catch(NumberFormatException e){
29: out.print("error!");
就没有问题,请问是什么原因?
楼主【wongshiang】截止到2008-07-18 13:49:31的历史汇总数据(不包括此帖):
发帖的总数量:7 发帖的总分数:120 每贴平均分数:17
回帖的总数量:10 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:3 结贴的总分数:40
无满意结贴数:1 无满意结贴分:20
未结的帖子数:4 未结的总分数:80
结贴的百分比:42.86 % 结分的百分比:33.33 %
无满意结贴率:33.33 % 无满意结分率:50.00 %
楼主该结一些帖子了
String str ="5.983777";
float a = Float.parseFloat(str);
double b = Double.parseDouble(str);
System.out.println(a);
System.out.println(b);
}你看看input1的内容到底是什么
不知道是不是跟没写(String)有关系.
<HTML>
<BODY BGCOLOR=cyan>
<form name=form action="" method="post">
<input type=text name=input1>
<input type=submit name=submit value=提交>
</form>
<%!
class Circle{
double r;
Circle(double r){
this.r=r;
}
double 获取面积(){
return Math.PI*r*r;
}
double 获取周长(){
return Math.PI*2*r;
}
}
%>
<%
String str=request.getParameter("input1");
double d=0;
try{
d=Double.parseDouble(str);
}
catch(NumberFormatException e){
out.print("error!");
}
Circle circle=new Circle(d);
%>
<p>圆的面积是:
<%=circle.获取面积()%>
<BR>
<p>圆的周长是:
<%=circle.获取周长()%>
<BR>
</BODY>
</HTML>
没有打印出str的内容,这个无法确定,但是,根据楼主所提供的信息,应该是这种原因了
if(str == null)return;