/** * Multiplies this BMoney by a double and returns a new object. * This object remains unchanged. * * @param val the double to multiply with * @return the product of this and given value */ public BMoney multiply(double val) { return new BMoney(doubleValue() * val, scale()); }
@Override public String doFormat(Object value) { if (value instanceof BMoney && (!isBlankZero() || !((BMoney)value).isZero())) { return format.format(((BMoney)value).doubleValue()); } return null; }
/** * Adds a BMoney to this value and returns a new object. * This object remains unchanged. * * @param val the money value to add * @return the sum of this and given value */ public BMoney add(BMoney val) { return new BMoney(unscaledValue().add(alignScale(val).unscaledValue()), scale()); }
/** * Check the scale of the given money value. * If it does not match the scale of this object, * scale it to the current scale of this object. * * @param val the value to be checked * @return the re-scaled value or the value itself if no rescaling necessary */ protected BMoney alignScale(BMoney val) { return val.scale() == scale() ? val : new BMoney(val.unscaledValue(), scale()); }
/** * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as a * <code>BMoney</code> with full precision.<br> * Notice that BMoney fields use two fields: * one for the value and * one for the scale (= name + "_2") * * @param name the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column * @return the column value (full precision); * if the value is SQL <code>NULL</code>, the value returned is * <code>null</code> in the Java programming language. */ public BMoney getBMoney (String name) { double value = getDouble(name); return wasNull() ? null : new BMoney (value, getInt(name + "_2")); }
double d = m.doubleValue(); short s = (short) m.scale();
private String debitCreditToString(BMoney money, boolean debit) { if (money == null) { return ""; } setScale(moneyFormat, money.scale()); return debit ? (moneyFormat.format(money) + debitString) : (" " + moneyFormat.format(money) + creditString); } }
money = new BMoney(value); if (minValue != null && money.compareTo(minValue) < 0) { errorMessage = MessageFormat.format(SwingSwingBundle.getString("MONEY VALUE MUST BE_>= {0}"), minValue); else if (maxValue != null && money.compareTo(maxValue) > 0) { errorMessage = MessageFormat.format(SwingSwingBundle.getString("MONEY VALUE MUST BE <= {0}"), maxValue);
/** * Divides a BMoney by this value and returns a new object. * This object remains unchanged. * * @param val the money value to multiply * @return the quotient of this and given value */ public double divide(BMoney val) { return doubleValue() / val.doubleValue(); }
@Override public String doFormat (Object object) { if (object != null) { if (blankZero) { if (object instanceof Double) { if (((Double) object) == 0.0d) { return ""; } } else if (object instanceof Float) { if (((Float) object) == 0.0f) { return ""; } } else if (object instanceof BMoney) { if (((BMoney) object).isZero()) { return ""; } } else if (object instanceof Number) { if (((Number) object).longValue() == 0) { return ""; } } } // else standard formatting */ return decimalFormat.format(object); } return ""; }
bmoneys[col] = bmoneys[col].add((BMoney)value); break;
/** * Inverts this money value. * * @return the negated money value */ public BMoney invert() { return new BMoney(unscaledValue().negate(), scale()); }
return new BMoney(value, FormatHelper.determineScale(value));
cell.setCellValue(money.doubleValue()); if (money.scale() > 0) { StringBuilder buf = new StringBuilder(fmt).append('.'); for (int j=0; j < money.scale(); j++) { buf.append('0');
/** * {@inheritDoc} * <p> * Overridden to set the scale from the money value */ @Override public void setPrintValue (Object value) { if (value instanceof BMoney) { setScale(((BMoney)value).scale()); // set scale! } super.setPrintValue(value); }
failed = ((BMoney) value).isZero();
/** * Divides a BMoney by double and returns a new object. * This object remains unchanged. * * @param val the value to divide this BMoney by * @return the quotient of this and given value */ public BMoney divide(double val) { return new BMoney(doubleValue() / val, scale()); }
/** * Subtracts a BMoney from this value and returns a new object. * This object remains unchanged. * * @param val the money value to subtract * @return this minus the given value */ public BMoney subtract(BMoney val) { return new BMoney(unscaledValue().subtract(alignScale(val).unscaledValue()), scale()); }