double cost=0.299999999998;
用java程序怎么样才能四舍五入输出
cost=0.30

解决方案 »

  1.   

    10分都懒得进来看。
    有专门的方法的。你看看math那各类
      

  2.   


    public class Test {
     public static void main( String[] argv ) {
     double   a   =   12.36587;   
         double   c0=   Math.floor(a   *10+.5)/10;                         //   c0   =   12.4   
         double   c1=   Math.floor(a   *100+.5)/100;                   //   c1   =   12.37   
         double   c2=   Math.floor(a   *1000+.5)/1000;             //   c2   =   12.366   
         double   c3=   Math.floor(a   *10000+.5)/10000;       //   c3   =   12.3659   
         System.out.println(c0)   ;   
         System.out.println(c1)   ;   
         System.out.println(c2)   ;   
         System.out.println(c3)   ;   
     }
     }