DecimalFormat df = new DecimalFormat("#.000000000");
 System.out.println(df.format(1.0));
 System.out.println(df.format(1.111111111111));1.000000000
1.111111111

解决方案 »

  1.   

    BigDecimal bd = new BigDecimal("1.11111111");
    System.out.println(bd);
      

  2.   

     DecimalFormat df = new DecimalFormat("#.000000000");
     System.out.println(df.format(1.0));
     System.out.println(df.format(1.111111111111));1.000000000
    1.111111111
    如果是1。0的时候就显示1。0。这样怎么做?
      

  3.   

    那就四舍五入了public int getRound(double dSource){
    int iRound
    //BigDecimal的构造函数参数类型是double
    BigDecimal deSource = new BigDecimal(dSource);
    //deSource.setScale(0,BigDecimal.ROUND_HALF_UP) 返回值类型 BigDecimal
    //intValue() 方法将BigDecimal转化为int
    iRound= deSource.setScale(0,BigDecimal.ROUND_HALF_UP).intValue();
    return iRound;
    }
      

  4.   

    也许要求有点过分,在数据库中它是float类型,取出来的时候,大数据老是用科学记数法显示,现在要完全恢复,尽量不数据丢失。还有没有办法?谢谢!!