把BigDecimal的值直接toString输出就可以了
BigDecimal num=new BigDecimal(1.234567890123456789011);
System.out.println(num.toString());

解决方案 »

  1.   

    我打错了
    把BigDecimal的值直接toString输出就可以了
    BigDecimal num=new BigDecimal("1.234567890123456789011");
    System.out.println(num.toString());
    另外,以后问问题还是请你虚心点
      

  2.   

    to pleonheart(只睡六小时) :
    首先感谢您帮助回答我的问题。请您看下我最上面的程序示例,BigDecimal初始化时候不允许赋字符串初始化的,而是赋了一个数值类型,初始赋字符串可以显示20位这个偶也知道,但是为什么赋了一个数值类型之后结果会。。
    可能你误解了我的意思,最上面说的话只是想让大家回答问题更加严谨一些,当然有些时候提出一些没有验证的假设可以给大家更多启发,但是我想既然大家都很忙还是劳累一下先验证再发表言论,这样更加好一些,我作为帖子的楼主应该有这个权利吧:)to skyboy0720(飞) :
    我相对你说的话上面就有,不用偶重复了吧,呵呵
      

  3.   

    我想你应该去查查,double 型的数据小数点后精确到多少位
      

  4.   

    double是15-16位数,这个偶知道
      

  5.   

    你输入的double在BigDecimal中被转化为long,至于提高精度的方法。
    你可以用上面所说的“输入字符串”,或是自己去改造这个类。    public BigDecimal(double val) {
    if (Double.isInfinite(val) || Double.isNaN(val))
        throw new NumberFormatException("Infinite or NaN"); /*
     * Translate the double into sign, exponent and mantissa, according
     * to the formulae in JLS, Section 20.10.22.
     */
    long valBits = Double.doubleToLongBits(val);
    int sign = ((valBits >> 63)==0 ? 1 : -1);
    int exponent = (int) ((valBits >> 52) & 0x7ffL);
    long mantissa = (exponent==0 ? (valBits & ((1L<<52) - 1)) << 1
         : (valBits & ((1L<<52) - 1)) | (1L<<52));
    exponent -= 1075;
    /* At this point, val == sign * mantissa * 2**exponent */ /*
     * Special case zero to to supress nonterminating normalization
     * and bogus scale calculation.
     */
    if (mantissa == 0) {
        intVal = BigInteger.ZERO;
        return;
    } /* Normalize */
    while((mantissa & 1) == 0) {    /*  i.e., Mantissa is even */
        mantissa >>= 1;
        exponent++;
    } /* Calculate intVal and scale */
    intVal = BigInteger.valueOf(sign*mantissa);
    if (exponent < 0) {
        intVal = intVal.multiply(BigInteger.valueOf(5).pow(-exponent));
        scale = -exponent;
    } else if (exponent > 0) {
        intVal = intVal.multiply(BigInteger.valueOf(2).pow(exponent));
    }
        }