Examples of unscaledValue()


Examples of java.math.BigDecimal.unscaledValue()

     */
    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

Examples of java.math.BigDecimal.unscaledValue()

         *
         * 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();
        int normalizedScale = unscaledValStr.length() - 1;
View Full Code Here

Examples of java.math.BigDecimal.unscaledValue()

      if (object == null) {
        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);
View Full Code Here

Examples of java.math.BigDecimal.unscaledValue()

        }
        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

Examples of java.math.BigDecimal.unscaledValue()

                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);
                        writeVarLong(b.longValue());
View Full Code Here

Examples of java.math.BigDecimal.unscaledValue()

                return 1;
            } else if (BigDecimal.ONE.equals(x)) {
                return 1;
            }
            int scale = x.scale();
            BigInteger b = x.unscaledValue();
            int bits = b.bitLength();
            if (bits <= 63) {
                if (scale == 0) {
                    return 1 + getVarLongLen(b.longValue());
                }
View Full Code Here

Examples of java.math.BigDecimal.unscaledValue()

        }
        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

Examples of java.math.BigDecimal.unscaledValue()

      // the standard rules below.
      isNegative = false; // except that the sign bit is ignored
    }
    bd = convertToBigDecimal(exponent, fracBits);
   
    return formatBigInteger(isNegative, bd.unscaledValue(), bd.scale());
  }

  private static BigDecimal convertToBigDecimal(int exponent, long fracBits) {
    byte[] joob = {
        (byte) (fracBits >> 48),  
View Full Code Here

Examples of java.math.BigDecimal.unscaledValue()

            return new BigRational((BigInteger)n,BigInteger.ONE);
        case 3: {
                BigDecimal decimal=(BigDecimal)n;
                // This method assumes that all BigDecimals actually have some decimal digits.
                assert decimal.scale()>0;
                return new BigRational(decimal.unscaledValue(),BigInteger.TEN.pow(decimal.scale()));
            }
        default:
            throw new IllegalArgumentException();
        }
    }
View Full Code Here

Examples of java.math.BigDecimal.unscaledValue()

            case Types.SQL_NUMERIC :
            case Types.SQL_DECIMAL :
                s += 8;

                BigDecimal bigdecimal = (BigDecimal) o;
                BigInteger bigint     = bigdecimal.unscaledValue();

                s += bigint.toByteArray().length;
                break;

            case Types.SQL_BOOLEAN :
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.