public MoneyAmount copy() { return MoneyAmount.of(getNumber(), getCurrency()); }
public MoneyAmount divide(long n) { return MoneyAmount.of(getNumber().longValue() / n, getCurrency()); }
protected MoneyAmount divide(MoneyAmount that) { Unit<?> unit = unit().divide(that.unit()); return MoneyAmount.of(((BigDecimal) getNumber()).divide((BigDecimal) that.getNumber()), unit); }
protected MoneyAmount times(MoneyAmount that) { Unit<?> unit = unit().multiply(that.unit()); return MoneyAmount.of(((BigDecimal) getNumber()).multiply((BigDecimal) that.getNumber()), unit); }
public MoneyAmount pow(int exp) { return MoneyAmount.of(((BigDecimal) getNumber()).pow(BigDecimal.valueOf(exp)), unit().pow(exp)); }
public MoneyAmount multiply(long n) { return MoneyAmount.of(getNumber().longValue() * n, getCurrency()); }
public MoneyAmount multiply(Number that) { return MoneyAmount.of(getNumber().doubleValue() * that.doubleValue(), getCurrency()); }
protected MoneyAmount minus(MoneyAmount that) { // MoneyAmount amount = that.to((Unit) getCurrency()); return MoneyAmount.of( this.getNumber().doubleValue() - that.getNumber().doubleValue(), getCurrency()); }
protected MoneyAmount plus(MoneyAmount that) { // Measure<BigDecimal, ?> amount = that.to((Unit) getCurrency()); return MoneyAmount.of( this.getNumber().doubleValue() + that.getNumber().doubleValue(), getCurrency()); }
/** * Returns the money amount corresponding to the specified generic amount. * * @param amount the raw amount. * @return the corresponding money amount stated in an existing {@link Currency}. * @throws ClassCastException if the SI unit of the specified amount is not a {@link Currency}. */ public static MoneyAmount of(QuantityAmount<IMoney> amount) { // MoneyAmount amountSI = amount.toSI(); return MoneyAmount.of( BigDecimal.valueOf(amount.getValue().doubleValue()), amount.unit().getSystemUnit()); }