Package java.math

Examples of java.math.BigDecimal.scale()


                                                                      DatatypeMessageProvider.MSG_NONE,
                                                                      new Object[] { "'" + content + "'" + " with fractionDigits = '"+ d.scale() +"'"
                                                                          , "'" + fFractionDigits + "'"}));
        }
        if ( (fFacetsDefined & DatatypeValidator.FACET_TOTALDIGITS)!=0 ) {
            int totalDigits = d.movePointRight(d.scale()).toString().length() -
                              ((d.signum() < 0) ? 1 : 0); // account for minus sign
            if ( totalDigits > fTotalDigits )
                throw new InvalidDatatypeValueException(
                                                       getErrorString(DatatypeMessageProvider.TOTALDIGITS_EXCEEDED,
                                                                      DatatypeMessageProvider.MSG_NONE,
View Full Code Here


        if (text.length() > 0) {
            ParsePosition parsePosition = new ParsePosition(0);
            BigDecimal numericAmount = (BigDecimal) FORMAT.parse(text, parsePosition);
            valid = (numericAmount != null &&
                numericAmount.scale() <= 2 &&
                numericAmount.signum() >= 0 &&
                parsePosition.getErrorIndex() == -1 &&
                parsePosition.getIndex() == text.length());
        }
View Full Code Here

  // 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");
  System.out.println(b2.precision())// 172. Number of digits in the "unscaled value". The precision of a zero value is 1.
View Full Code Here

  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");
  System.out.println(b3.precision())// 172. Number of digits in the "unscaled value". The precision of a zero value is 1.
View Full Code Here

  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
  MathContext mc = new MathContext(b3.precision() - b3.scale(), RoundingMode.DOWN);
View Full Code Here

  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

            BigDecimal s = BigDecimal.ZERO;
            for (int i = k; i < m; i++) {
                int scale = MatrixBigDecimal.GLOBAL_SCALE;
                s = s.add(QR[i][k].multiply(X[i][j]), new MathContext(scale));
            }
            int scale = Math.max(s.scale(), QR[k][k].scale());
            s = s.negate().divide(QR[k][k], scale, roundingMode);
            for (int i = k; i < m; i++) {
                int scale2 = MatrixBigDecimal.GLOBAL_SCALE;
                X[i][j] = X[i][j].add(s.multiply(QR[i][k], new MathContext(scale2)));
            }
View Full Code Here

            if (value == null) {
                return false;
            }
            DecimalStyle decimalStyle = context.getDecimalStyle();
            BigDecimal fraction = convertToFraction(value);
            if (fraction.scale() == 0) {  // scale is zero if value is zero
                if (minWidth > 0) {
                    if (decimalPoint) {
                        buf.append(decimalStyle.getDecimalSeparator());
                    }
                    for (int i = 0; i < minWidth; i++) {
View Full Code Here

                    for (int i = 0; i < minWidth; i++) {
                        buf.append(decimalStyle.getZeroDigit());
                    }
                }
            } else {
                int outputScale = Math.min(Math.max(fraction.scale(), minWidth), maxWidth);
                fraction = fraction.setScale(outputScale, RoundingMode.FLOOR);
                String str = fraction.toPlainString().substring(2);
                str = decimalStyle.convertNumberToI18N(str);
                if (decimalPoint) {
                    buf.append(decimalStyle.getDecimalSeparator());
View Full Code Here

                MathContext mc = new MathContext(compPrec);
                BigDecimal v
                    = new BigDecimal(value.unscaledValue(), scale, mc);

                BigDecimalLayout bdl
                    = new BigDecimalLayout(v.unscaledValue(), v.scale(),
                                           BigDecimalLayoutForm.SCIENTIFIC);

                char[] mant = bdl.mantissa();

                // Add a decimal point if necessary.  The mantissa may not
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.