float a = 43.8776f;
a= (float)(Math.round((double)a*100)/100.00);

解决方案 »

  1.   

    float ft = 134.3435f;
    int scale = 2;//设置位数
    int roundingMode = 4;//表示四舍五入,可以选择其他舍值方式,例如去尾,等等.
    BigDecimal bd = new BigDecimal((double)ft);
    bd = bd.setScale(scale,roundingMode);
    ft = bd.floatValue();
      

  2.   

    有个更简单的方法:
    import java.text.DecimalFormat;String a = new DecimalFormat("###,###,###.##").format(100.12345 );
     
    a='100.12'
      

  3.   

      float a = 123.2334f;
      float b = (float)(Math.round(a*100))/100;
      System.out.println("b="+b);