Examples of precision()


Examples of java.math.BigDecimal.precision()

    }
    else {
      bigNum = new BigDecimal( num.toString() ).stripTrailingZeros();
    }

    int integerPartLength = bigNum.precision() - bigNum.scale();
    int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();

    return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
  }
View Full Code Here

Examples of java.math.BigDecimal.precision()

    BigDecimal bigNum = getBigDecimalValue( str );
    if ( bigNum == null ) {
      return false;
    }

    int integerPartLength = bigNum.precision() - bigNum.scale();
    int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();

    return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
  }
View Full Code Here

Examples of java.math.BigDecimal.precision()

  //
  // Playing around with BigDecimal
  //
 
  BigDecimal b = BigDecimal.TEN;
  System.out.println(b.precision())// Number of digits in the "unscaled value". The precision of a zero value is 1.
  System.out.println(b.scale());
  System.out.println(b.signum());     // 1
 
  BigDecimal b2 =
      new BigDecimal("22222222222222222222222222222222222222222222222222222222222222222222222.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333");
View Full Code Here

Examples of java.math.BigDecimal.precision()

  System.out.println(b.scale());
  System.out.println(b.signum());     // 1
 
  BigDecimal b2 =
      new BigDecimal("22222222222222222222222222222222222222222222222222222222222222222222222.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333");
  System.out.println(b2.precision())// 172. Number of digits in the "unscaled value". The precision of a zero value is 1.
  System.out.println(b2.scale());      // 101
  System.out.println(b2.signum());     // 1

  BigDecimal b3 =
      new BigDecimal("-22222222222222222222222222222222222222222222222222222222222222222222222.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333");
View Full Code Here

Examples of java.math.BigDecimal.precision()

  System.out.println(b2.scale());      // 101
  System.out.println(b2.signum());     // 1

  BigDecimal b3 =
      new BigDecimal("-22222222222222222222222222222222222222222222222222222222222222222222222.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333");
  System.out.println(b3.precision())// 172. Number of digits in the "unscaled value". The precision of a zero value is 1.
  System.out.println(b3.scale());      // 101
  System.out.println(b3.signum());     // -1

  // RoundingMode.DOWN always goes towards 0
  // b3.precision() - b3.scale() will be the number of digits in the integer part of the BigDecimal
View Full Code Here

Examples of java.math.BigDecimal.precision()

  System.out.println(b3.scale());      // 101
  System.out.println(b3.signum());     // -1

  // RoundingMode.DOWN always goes towards 0
  // b3.precision() - b3.scale() will be the number of digits in the integer part of the BigDecimal
  MathContext mc = new MathContext(b3.precision() - b3.scale(), RoundingMode.DOWN);
  BigDecimal b3ROUNDED = b3.round(mc);
  BigDecimal b3FRACTIONALPART = b3.subtract(b3ROUNDED);
 
  System.out.println(b3ROUNDED);       // -22222222222222222222222222222222222222222222222222222222222222222222222
  System.out.println(b3FRACTIONALPART); // -0.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
View Full Code Here

Examples of java.math.BigDecimal.precision()

            BigDecimal S = broadhurstBBP(1, 1, a, mc).multiply(new BigDecimal(8),mc);
            /*
             * cache optimisation...
             */
            synchronized(Const.PI){                                   // added by l.bruninx, 2012-03-26.
               if (S.precision() > pi_cache.precision())pi_cache=S;   // added by l.bruninx, 2012-03-26.
            }                                                         // added by l.bruninx, 2012-03-26.
            return S;
        }
    } /* BigDecimalMath.pi */

 
View Full Code Here

Examples of java.math.BigDecimal.precision()

            /* s = s -(s/n-x/n/s^(n-1)) = s-(s-x/s^(n-1))/n; test correction s/n-x/s for being
             * smaller than the precision requested. The relative correction is (1-x/s^n)/n,
             */
            BigDecimal c = xhighpr.divide(s.pow(n - 1), mc);
            c = s.subtract(c);
            MathContext locmc = new MathContext(c.precision());
            c = c.divide(nth, locmc);
            s = s.subtract(c);
            if (Math.abs(c.doubleValue() / s.doubleValue()) < eps)
                break;
        }
View Full Code Here

Examples of java.math.BigDecimal.precision()

            final BigDecimal invx = exp(x.negate());
            /*
             * Relative error in inverse of invx is the same as the relative errror in invx.
             * This is used to define the precision of the result.
             */
            MathContext mc = new MathContext(invx.precision());
            return BigDecimal.ONE.divide(invx, mc);
        }
        else if (x.compareTo(BigDecimal.ZERO) == 0) {
            /* recover the valid number of digits from x.ulp(), if x hits the
             * zero. The x.precision() is 1 then, and does not provide this information.
View Full Code Here

Examples of java.math.BigDecimal.precision()

                /*
                 * Final powering by 10 means that the relative error of the result
                 * is 10 times the relative error of the base (First order binomial expansion).
                 * This looses one digit.
                 */
                MathContext mc = new MathContext(expxby10.precision() - exSc);
                /* Rescaling the powers of 10 is done in chunks of a maximum of 8 to avoid an invalid operation
                 * response by the BigDecimal.pow library or integer overflow.
                 */
                while (exSc > 0) {
                    int exsub = Math.min(8, exSc);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.