在JSP中如何将2.0转换为2,将2.1保持不变。
<%try{if(scheduleGoods.getGoods_volume() !=0)out.print(scheduleGoods.getGoods_volume());}catch(Exception e){}%>
getGoos_volume所求值为double型。

解决方案 »

  1.   

    2.0-->2 : int i = (int)2.0
    <%
    try { 
       if(scheduleGoods.getGoods_volume() !=0)
           out.print((int)scheduleGoods.getGoods_volume());
    }catch(Exception e){
    }
    %>
      

  2.   

    class Test1 
    {
    public static void main(String args[])
    {
    java.text.DecimalFormat  df  =new  java.text.DecimalFormat("#.##");  
    System.out.println(df.format(3.01));
    System.out.println(df.format(3.0));
    }
    }
      

  3.   

    楼主要的是不是这个效果
    double result = scheduleGoods.getGoods_volume();
    if(result != 0){
        if (result - (int)result > 0){
           out.print(result);
        }
        else out.print((int)result);
    }