Package java.math

Examples of java.math.BigDecimal.precision()


        }
        // enforce scale 12 to make the precision check right
        if (bd.scale() < kDefaultScale) {
            bd = bd.setScale(kDefaultScale);
        }
        if (bd.precision() > 38) {
            throw new RuntimeException(
                    "Decimal " + bd + " has more than " + kDefaultPrecision + " digits of precision.");
        }
        return bd;
    }
View Full Code Here


            return null;
        }
        final BigDecimal bd = new BigDecimal(
                new BigInteger(decimalBytes),
                        kDefaultScale, context);
        if (bd.precision() > 38) {
            throw new RuntimeException("Decimal " + bd + " has more than 38 digits of precision.");
        }
        return bd;
    }
View Full Code Here

        BigDecimal bigRight = toBigDecimal(right);
        try {
            return bigLeft.divide(bigRight);
        } catch (ArithmeticException e) {
            // set a DEFAULT precision if otherwise non-terminating
            int precision = Math.max(bigLeft.precision(), bigRight.precision()) + DIVISION_EXTRA_PRECISION;
            BigDecimal result = bigLeft.divide(bigRight, new MathContext(precision));
            int scale = Math.max(Math.max(bigLeft.scale(), bigRight.scale()), DIVISION_MIN_SCALE);
            if (result.scale() > scale) result = result.setScale(scale, BigDecimal.ROUND_HALF_UP);
            return result;
        }
View Full Code Here

     */
    public static String formatAmountConversionRate(double convRate) throws ISOException {
        if (convRate == 0)
            return null;
        BigDecimal cr = new BigDecimal(convRate);
        int x = 7 - cr.precision() + cr.scale();
        String bds = cr.movePointRight(cr.scale()).toString();
        if (x > 9)
            bds = ISOUtil.zeropad(bds, bds.length() + x - 9);
        String ret = ISOUtil.zeropadRight(bds, 7);
        return Math.min(9, x) + ISOUtil.takeFirstN(ret, 7);
View Full Code Here

        }
      } catch (final NumberFormatException e) {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value), e);
      }

      if (bigDecimalValue.precision() - bigDecimalValue.scale() > MAX_DIGITS
          || bigDecimalValue.scale() > MAX_DIGITS) {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
      }

      final int digits = bigDecimalValue.scale() >= 0 ?
View Full Code Here

          || bigDecimalValue.scale() > MAX_DIGITS) {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
      }

      final int digits = bigDecimalValue.scale() >= 0 ?
          Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) :
          bigDecimalValue.precision() - bigDecimalValue.scale();
      if (facets == null
          || (facets.getPrecision() == null || facets.getPrecision() >= digits)
          && (facets.getScale() == null || facets.getScale() >= bigDecimalValue.scale())) {
        result = bigDecimalValue.toPlainString();
View Full Code Here

        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
      }

      final int digits = bigDecimalValue.scale() >= 0 ?
          Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) :
          bigDecimalValue.precision() - bigDecimalValue.scale();
      if (facets == null
          || (facets.getPrecision() == null || facets.getPrecision() >= digits)
          && (facets.getScale() == null || facets.getScale() >= bigDecimalValue.scale())) {
        result = bigDecimalValue.toPlainString();
      } else {
View Full Code Here

 
  private boolean checkPrecisionAndScale(double numero, int precision, int scale){
    if (numero != 0.0) {
      BigDecimal bd = new BigDecimal(String.valueOf(numero));
      bd = bd.setScale(scale, BigDecimal.ROUND_HALF_DOWN);
      if (bd.precision() > precision)
        return false;
    }
    return true;
  }
View Full Code Here

    }
    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

    BigDecimal bigNum = getBigDecimalValue( charSequence );
    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

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.