Package java.math

Examples of java.math.BigDecimal.scale()


               Object value, boolean isSelected, boolean hasFocus,
               int row, int column) {
            BigDecimal valueAddedTaxPercentage = ((CatalogPieceOfFurniture)value).getValueAddedTaxPercentage();
            if (valueAddedTaxPercentage != null) {
              NumberFormat percentInstance = DecimalFormat.getPercentInstance();
              percentInstance.setMinimumFractionDigits(valueAddedTaxPercentage.scale() - 2);
              value = percentInstance.format(valueAddedTaxPercentage);
            } else {
              value = "";
            }
            setHorizontalAlignment(JLabel.RIGHT);
View Full Code Here


                        BigDecimal num = resultSet.getBigDecimal(index);
                        if (num == null) {
                            break;
                        }

                        if (num.scale() > 0) {
                            return new Double(num.doubleValue());
                        } else {
                            return new Long(num.longValue());
                        }
View Full Code Here

    }
   
    private static class BigDecimalColumnSerializer extends ColumnSerializer {
        protected void writeObject(ObjectOutput out, Object obj) throws IOException {
            BigDecimal val = (BigDecimal)obj;
            out.writeInt(val.scale());
            BigInteger unscaled = val.unscaledValue();
            byte[] bytes = unscaled.toByteArray();
            out.writeInt(bytes.length);
            out.write(bytes);
        }
View Full Code Here

   * @throws TransformationException if value is an incorrect input type or
   * the transformation fails
   */
  public Object transformDirect(Object value) throws TransformationException {
    BigDecimal result = BigDecimal.valueOf(((Number)value).doubleValue());
    result = result.setScale(Math.max(result.scale(), (value instanceof Double ? 16 : 8) - result.precision()));
    return result;
  }

  /**
   * Type of the incoming value.
View Full Code Here

                    BigDecimal num = rs.getBigDecimal(columnNumber);
                    if (num == null) {
                        break;
                    }
                    if (num.scale() > 0) {
                        newprop.setFloatValue(num.doubleValue());
                    } else {
                        newprop.setIntegerValue(num.longValue());
                    }
View Full Code Here

    return x.divide(y);
  }
 
  public static Object divide(BigDecimal x, BigDecimal y) {
    BigDecimal bd = x.divide(y, Math.max(16, x.scale() + y.precision() + 1), RoundingMode.HALF_UP).stripTrailingZeros();
    return bd.setScale(Math.max(x.scale(), bd.scale()));
  }

  // ================== Function = abs =====================

  public static int abs(int x) {
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

            if (BigDecimal.ZERO.equals(x)) {
                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

            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

    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.