/** * 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()); }
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); } }
/** * Returns the smalles positive value.<br> * Ex.: if scale is 2 --> 0.01 will be returned. * * @return the smalles positive value */ public BMoney smallestPositive() { return new BMoney(new BigDecimal(new BigInteger(new byte[] { 1 })).movePointLeft(scale())); }
/** * Inverts this money value. * * @return the negated money value */ public BMoney invert() { return new BMoney(unscaledValue().negate(), scale()); }
/** * {@inheritDoc} * <p> * Overridden to set the scale from the money value */ @Override public void setFormValue (Object object) { if (object instanceof BMoney) { setScale(((BMoney)object).scale()); // set scale! } super.setFormValue(object); }
/** * 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()); }
/** * 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()); }
/** * {@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); }
/** * 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()); }
/** * 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()); }
@Override protected DecimalFormat getFormat(FxTableCell<?, BMoney> tableCell, BMoney item) { DecimalFormat fmt = tableCell.getColumnConfiguration().getNumberFormat(); if (fmt == null) { // no format: use default format and set scale from money value fmt = new DecimalFormat(FormatHelper.getMoneyPattern()); FormatHelper.setScale(fmt, item.scale()); } return fmt; }
short s = (short) m.scale();
FormatHelper.setScale(format, ((BMoney) value).scale()); setValue(format.format(value)); if (fmt == null) {