Package java.math

Examples of java.math.BigDecimal.scale()


        // TODO: no need to calculate every time.
        if (isZero()) {
            return 0;
        }
        BigDecimal val = value.abs().stripTrailingZeros();
        return val.precision() - val.scale();
    }

    @JRubyMethod(name = "sqrt", required = 1)
    public IRubyObject sqrt(IRubyObject arg) {
        Ruby runtime = getRuntime();
View Full Code Here


        //                       new Object[] { "'" + content +"'"}));
        //}


        if ( isScaleDefined == true ) {
            if (d.scale() > fScale)
                throw new InvalidDatatypeValueException(
                                                        getErrorString(DatatypeMessageProvider.ScaleExceeded,
                                                                        DatatypeMessageProvider.MSG_NONE,
                                                                        new Object[] { content}));
        }
View Full Code Here

                                                        getErrorString(DatatypeMessageProvider.ScaleExceeded,
                                                                        DatatypeMessageProvider.MSG_NONE,
                                                                        new Object[] { content}));
        }
        if ( isPrecisionDefined == true ) {
            int precision = d.movePointRight(d.scale()).toString().length() -
                            ((d.signum() < 0) ? 1 : 0); // account for minus sign
            if (precision > fPrecision)
                throw new InvalidDatatypeValueException(
                                getErrorString(DatatypeMessageProvider.PrecisionExceeded,
                                 DatatypeMessageProvider.MSG_NONE,
View Full Code Here

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

        int intLength = bigDecimal.precision() - bigDecimal.scale();
        if (integral >= intLength) {
            int factionLength = bigDecimal.scale() < 0 ? 0 : bigDecimal.scale();
            return fractional >= factionLength;
        } else {
            return false;
View Full Code Here

            bigDecimal = new BigDecimal(num.toString()).stripTrailingZeros();
        }

        int intLength = bigDecimal.precision() - bigDecimal.scale();
        if (integral >= intLength) {
            int factionLength = bigDecimal.scale() < 0 ? 0 : bigDecimal.scale();
            return fractional >= factionLength;
        } else {
            return false;
        }
    }
View Full Code Here

            bigDecimal = new BigDecimal(num.toString()).stripTrailingZeros();
        }

        int intLength = bigDecimal.precision() - bigDecimal.scale();
        if (integral >= intLength) {
            int factionLength = bigDecimal.scale() < 0 ? 0 : bigDecimal.scale();
            return fractional >= factionLength;
        } else {
            return false;
        }
    }
View Full Code Here

            // older platforms.
            BigDecimal dec = new BigDecimal(Double.toString(d));

            // See how many trailing zeros we have after the decimal point.
            long unscaledValue = dec.unscaledValue().longValue();
            int scale = dec.scale();
            while (scale > 0 && unscaledValue % 10 == 0) {
                scale--;
                unscaledValue /= 10;
            }
View Full Code Here

                scale--;
                unscaledValue /= 10;
            }

            // If we have trailing zeros after the decimal point, remove them.
            if (scale != dec.scale()) {
                dec = BigDecimal.valueOf(unscaledValue, scale);
            }

            // Finally, convert the value to a string. The method
            // BigDecimal.toPlainString() formats the number the way we want
View Full Code Here

    public static DecimalValue decimalDivide(NumericValue a, NumericValue b) throws XPathException {
        final BigDecimal A = a.getDecimalValue();
        final BigDecimal B = b.getDecimalValue();
        int scale = Math.max(DecimalValue.DIVIDE_PRECISION,
                        Math.max(A.scale(), B.scale()));
        try {
            BigDecimal result = A.divide(B, scale, BigDecimal.ROUND_HALF_DOWN);
            return new DecimalValue(result);
        } catch (ArithmeticException err) {
            if (b.compareTo(0) == 0) {
View Full Code Here

        // Check overall
        if (type==DataType.DECIMAL)
        {   // Convert to Decimal
            BigDecimal dv = ObjectUtils.toDecimal(n);
            int prec = dv.precision();
            int scale = dv.scale();
            // check precision and scale
            double size = getSize();
            int reqPrec = (int)size;
            int reqScale =((int)(size*10)-(reqPrec*10));
            if ((prec-scale)>(reqPrec-reqScale) || scale>reqScale)
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.