Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio n. 12
0
 public Money dividedBy(BigDecimal divisor, int roundingMode) {
   BigDecimal newAmount = amount.divide(divisor, roundingMode);
   return Money.valueOf(newAmount, currency);
 }
Esempio n. 13
0
 public Money plus(Money other) {
   assertHasSameCurrencyAs(other);
   return Money.valueOf(amount.add(other.amount), currency);
 }
Esempio n. 14
0
 public boolean isZero() {
   return equals(Money.valueOf(0.0, currency));
 }
Esempio n. 15
0
 public Money abs() {
   return Money.valueOf(amount.abs(), currency);
 }
Esempio n. 16
0
 public Money negated() {
   return Money.valueOf(amount.negate(), currency);
 }