Exemplo n.º 1
0
 /** 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);
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 /**
  * 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);
 }
Exemplo n.º 6
0
 /**
  * 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);
 }
Exemplo n.º 7
0
 /**
  * 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);
 }
Exemplo n.º 8
0
 /**
  * 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);
 }
Exemplo n.º 9
0
 /**
  * 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);
 }
Exemplo n.º 10
0
 public Money applying(Ratio ratio, int scale, int roundingRule) {
   BigDecimal newAmount = ratio.times(amount).decimalValue(scale, roundingRule);
   return Money.valueOf(newAmount, currency);
 }
Exemplo n.º 11
0
 /**
  * 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);
 }
Exemplo n.º 12
0
 public Money dividedBy(BigDecimal divisor, int roundingMode) {
   BigDecimal newAmount = amount.divide(divisor, roundingMode);
   return Money.valueOf(newAmount, currency);
 }
Exemplo n.º 13
0
 public Money plus(Money other) {
   assertHasSameCurrencyAs(other);
   return Money.valueOf(amount.add(other.amount), currency);
 }
Exemplo n.º 14
0
 public boolean isZero() {
   return equals(Money.valueOf(0.0, currency));
 }
Exemplo n.º 15
0
 public Money abs() {
   return Money.valueOf(amount.abs(), currency);
 }
Exemplo n.º 16
0
 public Money negated() {
   return Money.valueOf(amount.negate(), currency);
 }