本文整理汇总了Java中javax.money.MonetaryAmount.add方法的典型用法代码示例。如果您正苦于以下问题:Java MonetaryAmount.add方法的具体用法?Java MonetaryAmount.add怎么用?Java MonetaryAmount.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.money.MonetaryAmount
的用法示例。
在下文中一共展示了MonetaryAmount.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import javax.money.MonetaryAmount; //导入方法依赖的package包/类
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
MonetaryOperator minorRounding = Monetary
.getRounding(RoundingQueryBuilder.of().set("scale", 2).set(RoundingMode.HALF_UP).build());
MonetaryAmount amt = amount.with(minorRounding);
MonetaryAmount mp = amt.with(MonetaryOperators.minorPart());
if (mp.isGreaterThanOrEqualTo(
Monetary.getDefaultAmountFactory().setCurrency(amount.getCurrency()).setNumber(0.03)
.create())) {
// add
return amt.add(Monetary.getDefaultAmountFactory().setCurrency(amt.getCurrency())
.setNumber(new BigDecimal("0.05")).create().subtract(mp));
} else {
// subtract
return amt.subtract(mp);
}
}
示例2: main
import javax.money.MonetaryAmount; //导入方法依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(BigDecimal.TEN, currency);
MonetaryAmount money2 = FastMoney.of(BigDecimal.TEN, currency);
MonetaryAmount addResult = money.add(money2);//BRL 20 Money implementation
MonetaryAmount subtractResult = money2.subtract(addResult);//BRL -10 FastMoney implementation
}
示例3: main
import javax.money.MonetaryAmount; //导入方法依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB);
CurrencyConversion currencyConversion = provider.getCurrencyConversion(dollar);
MonetaryAmount result = currencyConversion.apply(money2);
MonetaryAmount monetaryAmount = money.add(result);
}
示例4: main
import javax.money.MonetaryAmount; //导入方法依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
MonetaryAmount result = money.add(money2);//javax.money.MonetaryException: Currency mismatch: USD/BRL
}
示例5: main
import javax.money.MonetaryAmount; //导入方法依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
LocalDate localDate = Year.of(2011).atMonth(Month.JANUARY).atDay(9);
LocalDate[] localDates = Stream.of(localDate, localDate.minusDays(1L), localDate.minusDays(2L),
localDate.minusDays(3L)).sorted(Comparator.<LocalDate>naturalOrder().reversed()).toArray(LocalDate[]::new);
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF_HIST);
ConversionQuery query = ConversionQueryBuilder.of().setTermCurrency(dollar).set(localDates).build();
CurrencyConversion currencyConversion = provider.getCurrencyConversion(query);
MonetaryAmount result = currencyConversion.apply(money2);
MonetaryAmount sum = money.add(result);
}
示例6: main
import javax.money.MonetaryAmount; //导入方法依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
LocalDate localDate = Year.of(2009).atMonth(Month.JANUARY).atDay(9);
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF_HIST);
ConversionQuery query = ConversionQueryBuilder.of().setTermCurrency(dollar).set(localDate).build();
CurrencyConversion currencyConversion = provider.getCurrencyConversion(query);
MonetaryAmount result = currencyConversion.apply(money2);
MonetaryAmount monetaryAmount = money.add(result);
System.out.println(monetaryAmount);
}
示例7: sum
import javax.money.MonetaryAmount; //导入方法依赖的package包/类
/**
* Adds two monetary together
* @param a the first operand
* @param b the second operand
* @return the sum of {@code a} and {@code b}
* @throws NullPointerException if a o b be null
* @throws MonetaryException if a and b have different currency
*/
public static MonetaryAmount sum(MonetaryAmount a, MonetaryAmount b){
MoneyUtils.checkAmountParameter(Objects.requireNonNull(a), Objects.requireNonNull(b.getCurrency()));
return a.add(b);
}