DecimalFormat df = new DecimalFormat("#0.00");
System.out.println(df.format(val, new StringBuffer(), new FieldPosition(0)).toString());

解决方案 »

  1.   

    import java.math.*; 
    …… 
    方法1: 
    float f = 34.232323; 
    BigDecimal b = new BigDecimal(f); 
    float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); 
    // b.setScale(2, BigDecimal.ROUND_HALF_UP) 表明四舍五入,保留两位小数 
    方法2: 
    float scale = 34.236323; 
    DecimalFormat fnum = new DecimalFormat("##0.00"); 
    String dd=fnum.format(scale);   
    System.out.println(dd);
      

  2.   

    最简单的办法,
    float a = 1.23456;
    int b = a * 100 + 0.5;
    float c = b/100 ;
      

  3.   

    java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
    double x = 34.236323;
    System.out.println(df.format(x).toString());
      

  4.   

    先乘100,调用java.lang.Math类中的round()方法,请值转换成double,再除10。
      

  5.   

    DecimalFormat df = new DecimalFormat("#0.00");
    System.out.println(df.format(val, new StringBuffer(), new FieldPosition(0)).toString());
    这样做最好了!