java.text.DecimalFormat df = new java.text.DecimalFormat("########.0000");
float j = (new Float(df.format(i))).floatValue();

解决方案 »

  1.   

    float a(float in,int n)
    {
          for(;n>0;n--)
            in = in *10;      in = in +0.5;
          int temp;
          temp = (int)in;
          in = (float)temp;
          return in;
    }
      

  2.   

    double d = 123.654321;
    java.text.DecimalFormat df = new java.text.DecimalFormat("########.0000");
    String s = new String(df.format(d) ;
      

  3.   

    float i;
    i=1.1178f;
    Math.round(i*10000)/10000.0;
    System.out.println("i="+Math.round(i*10000)/10000.0);
      

  4.   

    1位小数就是Math.round(XX*10)/102位小数就是Math.round(XX*100)/100