四舍五入总会吧
我是菜鸟一个,但写写还可以的(int)Math.ceil((double)Integer.parseInt(num1)/50)  15.3265可以先×100
后/100.0

解决方案 »

  1.   

    temp1= String.valueOf(Float.parseFloat(totalMark)/totalMark2*100);
    dotI = temp1.indexOf(".");
    tempLen = temp1.length();
    if (dotI+3<=tempLen){tempLen =dotI+3;}
    temp1=temp1.substring(0,tempLen);不知有没有好的方法
      

  2.   

    double aa=15.3265;
    double bb;bb=(aa*100)/100.0;
    System.out.println(String.valueOf(bb));But the result is 15.3265 still
      

  3.   

    double aa=15.3265;
    double bb;bb=(aa*100)/100.0;
    System.out.println(String.valueOf(bb));But the result is 15.3265 still
      

  4.   


    double aa = 123.23232323;
    int bb = (int)(aa * 100);
    System.out.println(bb/100.00);
      

  5.   

    float a=5.3445;
    BigDecimal b=new BigDecimal(a);
    BigDecimal c=b.setScale(2,BigDecimal.ROUND_HALF_UP))//四舍五入保留二位;
    a=c.floatValue();除了四舍五入外,还有截断,五舍六入等保留方法。
    不过要import java.math.*
      

  6.   

    或者
    aa = Math.round(aa*100)/100.00
      

  7.   

    double aa=15.3265;
    double bb;
    double cc;bb=aa*100;
    cc= (int)Math.round(bb)/100.0 ; 
    out.println ("the result is :" + cc+"<br>");  //15.33
      

  8.   

    double x = 15.3265;
    double y;
    y = (int)Math.round(x * 100)/100.00;
    out.println("the result is :"+ y);
      

  9.   

    /**
         * 四舍五入
         * @param f double 类型,要进行四舍五入的数字
         * @param position 要保留小数位的个数
         * @return String
         * @throws Exception
         */
        public String round (double f,int position) throws Exception {
            String sf = String.valueOf(f);
            int i = sf.indexOf(".");
            String s1 = "" ,s2 = "";
            if(sf.substring(i+1).length() <= position){
                return String.valueOf(f);
            }
            if(position == 0){
                s1 = sf.substring(i-1,i);
                s2 = sf.substring(i+position+1,i+position+2);
                if(Integer.parseInt(s2) >=5 ){
                    s1 = String.valueOf(Integer.parseInt(s1)+1);
                }
                return sf.substring(0,i-1)+s1;
            }else{
                s1 = sf.substring(i+position, i+position+1);
                s2 = sf.substring(i+position+1,i+position+2);            if(Integer.parseInt(s2) >=5 ){
                    s1 = String.valueOf(Integer.parseInt(s1)+1);
                }
                return sf.substring(0,i+position)+s1;
            }    }
      

  10.   

    别考虑太复杂了,如果你仅仅想要前两位,可以format一下,相关类是:java.util.NumberFormt,java.util.DecimalFormt
      

  11.   

    太好了,谢谢大家!
    只要小数点两位的话 diewikwang(coconut) ,lgs6715(),sasa_sasa(乡巴佬) 的最简单 
     huanxiangzhe24(huanxiangzhe24)  的是比较好
     cui_yihao(pg) 这个人比较有钻的精神,
    <%@page import="java.math.*"%>
    <%
    double aa=15.3265;
    double bb;
    double cc;bb=aa*100;
    cc=(int)Math.round(bb)/100.00;
    out.println ("the result is :" + cc+"<br>");  //15.33
    double a=82.6984;
    BigDecimal b=new BigDecimal(a);
    BigDecimal c=b.setScale(3,BigDecimal.ROUND_HALF_UP);//82.698
    BigDecimal d=b.setScale(2,BigDecimal.ROUND_HALF_UP); //82.70
    BigDecimal e=b.setScale(1,BigDecimal.ROUND_HALF_UP); //82.7
    BigDecimal f=b.setScale(0,BigDecimal.ROUND_HALF_UP); //83
    out.println ("the result is :"+c+"<br>");
    out.println ("the result is :"+d+"<br>");
    out.println ("the result is :"+e+"<br>");
    out.println ("the result is :"+f+"<br>");
    %>好了,大家给了我这么多的方法,给了我这么多的鼓励,我加分来谢谢大家
    来者有份!同时为了让更多需要这种帮助的人能得到大家的帮助,所以暂不结贴,
    但这贴以后的发贴的同志,将不会有分了,不便之处,敬请谅解!