/** Return the max of <code>a</code> or <code>0</code> */ public static Money notBelowZero(Money a) { Money zero = Money.valueOf(0.00, a.getCurrency()); return Money.max(zero, a); }
/** * WARNING: Because of the indefinite precision of double, this method must round off the value. */ public static Money euros(double amount) { return Money.valueOf(amount, Money.EUR); }
/** * This creation method is safe to use. It will adjust scale, but will not round off the amount. */ public static Money euros(BigDecimal amount) { return Money.valueOf(amount, Money.EUR); }
/** * This creation method is safe to use. It will adjust scale, but will not round off the amount. */ public static Money dollars(BigDecimal amount) { return Money.valueOf(amount, Money.USD); }
/** * This creation method is safe to use. It will adjust scale, but will not round off the amount. */ public static Money valueOf(BigDecimal amount, Currency currency) { return Money.valueOf(amount, currency, Rounding.UNNECESSARY); }
/** * Because of the indefinite precision of double, this method must round off the value. This * method gives the client control of the rounding mode. */ public static Money valueOf(double dblAmount, Currency currency, int roundingMode) { BigDecimal rawAmount = new BigDecimal(dblAmount); return Money.valueOf(rawAmount, currency, roundingMode); }
/** * WARNING: Because of the indefinite precision of double, thismethod must round off the value. */ public static Money dollars(double amount) { return Money.valueOf(amount, Money.USD); }
/** * This probably should be Currency responsibility. Even then, it may need to be customized for * specialty apps because there are other cases, where the smallest increment is not the smallest * unit. */ Money minimumIncrement() { BigDecimal one = new BigDecimal(1); BigDecimal increment = one.movePointLeft(currency.getDefaultFractionDigits()); return Money.valueOf(increment, currency); }
/** * WARNING: Because of the indefinite precision of double, this method must round off the value. */ public static Money valueOf(double dblAmount, Currency currency) { return Money.valueOf(dblAmount, currency, Money.DEFAULT_ROUNDING_MODE); }
public Money applying(Ratio ratio, int scale, int roundingRule) { BigDecimal newAmount = ratio.times(amount).decimalValue(scale, roundingRule); return Money.valueOf(newAmount, currency); }
/** * TODO: BigDecimal.multiply() scale is sum of scales of two multiplied numbers. So what is scale * of times? */ public Money times(BigDecimal factor, int roundingMode) { return Money.valueOf(amount.multiply(factor), currency, roundingMode); }
public Money dividedBy(BigDecimal divisor, int roundingMode) { BigDecimal newAmount = amount.divide(divisor, roundingMode); return Money.valueOf(newAmount, currency); }
public Money plus(Money other) { assertHasSameCurrencyAs(other); return Money.valueOf(amount.add(other.amount), currency); }
public boolean isZero() { return equals(Money.valueOf(0.0, currency)); }
public Money abs() { return Money.valueOf(amount.abs(), currency); }
public Money negated() { return Money.valueOf(amount.negate(), currency); }