/** * 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()); }
/** * Inverts this money value. * * @return the negated money value */ public BMoney invert() { return new BMoney(unscaledValue().negate(), scale()); }
@Override public DMoney add(BMoney val) { return new DMoney(unscaledValue().add(alignScale(val).unscaledValue()), scale()); }
@Override public DMoney subtract(BMoney val) { return new DMoney(unscaledValue().subtract(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()); }