Package java.math

Examples of java.math.BigDecimal.scale()


    ** calculates the scale according to actual values.  Beetle 3901
    */
    result.setBigDecimal(dividendBigDecimal.divide(
                  divisorBigDecimal,
                  scale > -1 ? scale :
                  Math.max((dividendBigDecimal.scale() +
                      SQLDecimal.getWholeDigits(divisorBigDecimal) +
                      1),
                    NumberDataValue.MIN_DECIMAL_DIVIDE_SCALE),
                  BigDecimal.ROUND_DOWN));
   
View Full Code Here


            }
            enumCheck(d, enumDecimal);
        }

        if ( (fFacetsDefined & DatatypeValidator.FACET_FRACTIONDIGITS)!=0 ) {
            if ( d.scale() > fFractionDigits )
                throw new InvalidDatatypeValueException(
                                                       getErrorString(DatatypeMessageProvider.FRACTION_EXCEEDED,
                                                                      DatatypeMessageProvider.MSG_NONE,
                                                                      new Object[] { content}));
        }
View Full Code Here

                                                       getErrorString(DatatypeMessageProvider.FRACTION_EXCEEDED,
                                                                      DatatypeMessageProvider.MSG_NONE,
                                                                      new Object[] { content}));
        }
        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

     * represented as a Rational.
     */
    public Rational(BigDecimal value)
    {
        BigDecimal trimmedValue = value.stripTrailingZeros();
        BigInteger denominator = BigInteger.TEN.pow(trimmedValue.scale());
        BigInteger numerator = trimmedValue.unscaledValue();
        BigInteger gcd = numerator.gcd(denominator);
        this.numerator = numerator.divide(gcd).longValue();
        this.denominator = denominator.divide(gcd).longValue();
    }
View Full Code Here

         *     Byte 6 ~ N: the normalized decimal part with sign.
         *
         * Get the scale and the unscaled value of this BigDecimal..
         */
        BigDecimal valNoTrailZeros = val.stripTrailingZeros();
        int scale = valNoTrailZeros.scale();
        BigInteger unscaledVal = valNoTrailZeros.unscaledValue();
        int sign = valNoTrailZeros.signum();
       
        /* Then do the normalization. */
        String unscaledValStr = unscaledVal.abs().toString();
View Full Code Here

                    request.put("item_" + lineNumber + "_productName", item.getString("description"));
                }
                // get the quantity..
                BigDecimal quantity = item.getBigDecimal("quantity");
                // test quantity if INT pass as is; if not pass as 1
                if (quantity.scale() > 0) {
                    request.put("item_" + lineNumber + "_quantity", "1");
                } else {
                    request.put("", Integer.toString(quantity.intValue()));
                }
                // set the amount to 0.0000 -- we will send a total too.
View Full Code Here

        output.writeVarInt(NULL, true);
        return;
      }
      BigDecimal value = (BigDecimal)object;
      bigIntegerSerializer.write(kryo, output, value.unscaledValue());
      output.writeInt(value.scale(), false);
    }

    public BigDecimal read (Kryo kryo, Input input, Class<BigDecimal> type) {
      BigInteger unscaledValue = bigIntegerSerializer.read(kryo, input, null);
      if (unscaledValue == null) return null;
View Full Code Here

        Number unwrapped;

        if (n instanceof LazilyParsedNumber) {
            LazilyParsedNumber lpn = (LazilyParsedNumber) n;
            BigDecimal bigDecimal = new BigDecimal(lpn.toString());
            if (bigDecimal.scale() <= 0) {
                if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
                    unwrapped = bigDecimal.intValue();
                } else {
                    unwrapped = bigDecimal.longValue();
                }
View Full Code Here

            throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
        }
        BigDecimal bd = value.divide(dec.value, value.scale() + DIVIDE_SCALE_ADD, BigDecimal.ROUND_HALF_DOWN);
        if (bd.signum() == 0) {
            bd = BigDecimal.ZERO;
        } else if (bd.scale() > 0) {
            if (!bd.unscaledValue().testBit(0)) {
                String s = bd.toString();
                int i = s.length() - 1;
                while (i >= 0 && s.charAt(i) == '0') {
                    i--;
View Full Code Here

            if (BigDecimal.ZERO.equals(x)) {
                writeByte((byte) DECIMAL_0_1);
            } else if (BigDecimal.ONE.equals(x)) {
                writeByte((byte) (DECIMAL_0_1 + 1));
            } else {
                int scale = x.scale();
                BigInteger b = x.unscaledValue();
                int bits = b.bitLength();
                if (bits <= 63) {
                    if (scale == 0) {
                        writeByte((byte) DECIMAL_SMALL_0);
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.