当前位置: 首页>>代码示例>>Java>>正文


Java MonetaryAmount.getCurrency方法代码示例

本文整理汇总了Java中javax.money.MonetaryAmount.getCurrency方法的典型用法代码示例。如果您正苦于以下问题:Java MonetaryAmount.getCurrency方法的具体用法?Java MonetaryAmount.getCurrency怎么用?Java MonetaryAmount.getCurrency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.money.MonetaryAmount的用法示例。


在下文中一共展示了MonetaryAmount.getCurrency方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
/**
 * Method that converts the source {@link MonetaryAmount} to an
 * {@link MonetaryAmount} based on the {@link ExchangeRate} of this
 * conversion.
 *
 * @param amount The source amount
 * @return The converted amount, never null.
 * @throws CurrencyConversionException if conversion failed, or the required data is not available.
 * @see #getExchangeRate(MonetaryAmount)
 */
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
    if (termCurrency.equals(Objects.requireNonNull(amount).getCurrency())) {
        return amount;
    }
    ExchangeRate rate = getExchangeRate(amount);
    if (rate==null || !amount.getCurrency().equals(rate.getBaseCurrency())) {
        throw new CurrencyConversionException(amount.getCurrency(),
                this.termCurrency, this.conversionContext);
    }

    NumberValue factor = rate.getFactor();
    factor = roundFactor(amount, factor);

    Integer scale = rate.getContext().get(KEY_SCALE, Integer.class);
    if(scale==null || scale < 0) {
    	return amount.multiply(factor).getFactory().setCurrency(rate.getCurrency()).create();
    } else {
    	return amount.multiply(factor).getFactory().setCurrency(rate.getCurrency()).create().with(MonetaryOperators.rounding(scale));
    }
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:32,代码来源:AbstractCurrencyConversion.java

示例2: serialize

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
@Override
public void serialize(final MonetaryAmount value, final JsonGenerator generator, final SerializerProvider provider)
        throws IOException {

    final CurrencyUnit currency = value.getCurrency();
    @Nullable final String formatted = format(value, provider);

    generator.writeStartObject();
    {
        generator.writeObjectField(names.getAmount(), writer.write(value));
        generator.writeObjectField(names.getCurrency(), currency);

        if (formatted != null) {
            generator.writeStringField(names.getFormatted(), formatted);
        }
    }
    generator.writeEndObject();
}
 
开发者ID:zalando,项目名称:jackson-datatype-money,代码行数:19,代码来源:MonetaryAmountSerializer.java

示例3: apply

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
@Override
public MonetaryAmount apply(MonetaryAmount amount) {
	Objects.requireNonNull(amount, "Amount required.");
	CurrencyUnit currency = amount.getCurrency();
	int scale = scaleOptional == null ? currency.getDefaultFractionDigits(): scaleOptional;
	BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode);
	return amount.getFactory().setNumber(value).create();
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:9,代码来源:RoudingMonetaryAmountOperator.java

示例4: setAmount

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
/**
 * Converts (if necessary) the given {@link MonetaryAmount} to a new {@link MonetaryAmount}
 * instance, hereby supporting the {@link MonetaryContext} given.
 *
 * @param amount the amount to be converted, if necessary.
 * @return an according Money instance.
 */
@Override
public MonetaryAmountFactory<T> setAmount(MonetaryAmount amount) {
    this.currency = amount.getCurrency();
    this.number = amount.getNumber().numberValue(BigDecimal.class);
    this.monetaryContext = MonetaryContextBuilder.of(defaultMonetaryContext.getAmountType())
            .importContext(amount.getContext()).build();
    return this;
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:16,代码来源:AbstractAmountBuilder.java

示例5: from

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
public static FastMoney from(MonetaryAmount amount) {
    if (FastMoney.class.isInstance(amount)) {
        return FastMoney.class.cast(amount);
    }
    return new FastMoney(amount.getNumber(), amount.getCurrency(), false);
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:7,代码来源:FastMoney.java

示例6: main

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
public  static  void main(String[] args) {

        MonetaryAmount money = Money.of(10, Monetary.getCurrency("BRL"));
        CurrencyUnit currency = money.getCurrency();
        Number number = money.getNumber();

    }
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:8,代码来源:RetrieveInformationMethods.java

示例7: queryFrom

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
/**
 * Gets the amount in minor units as a {@code long}.
 * <p>
 * This returns the monetary amount in terms of the minor units of the
 * currency, truncating the amount if necessary. For example, 'EUR 2.35'
 * will return 235, and 'BHD -1.345' will return -1345.
 * <p>
 * This method matches the API of {@link java.math.BigDecimal}.
 *
 * @return the minor units part of the amount
 * @throws ArithmeticException
 *             if the amount is too large for a {@code long}
 */
@Override
public Long queryFrom(MonetaryAmount amount) {
	Objects.requireNonNull(amount, "Amount required.");
	BigDecimal number = amount.getNumber().numberValue(BigDecimal.class);
	CurrencyUnit cur = amount.getCurrency();
	int scale = cur.getDefaultFractionDigits();
	if(scale<0){
		scale = 0;
	}
	number = number.setScale(scale, RoundingMode.DOWN);
	return number.movePointRight(number.scale()).longValueExact();
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:26,代码来源:ConvertMinorPartQuery.java

示例8: checkAmountParameter

import javax.money.MonetaryAmount; //导入方法依赖的package包/类
/**
 * Method to check if a currency is compatible with this amount instance.
 *
 * @param amount       The monetary amount to be compared to, never null.
 * @param currencyUnit the currency unit to compare, never null.
 * @throws MonetaryException If the amount is null, or the amount's {@link CurrencyUnit} is not
 *                           compatible, meaning has a different value of
 *                           {@link CurrencyUnit#getCurrencyCode()}).
 */
public static void checkAmountParameter(MonetaryAmount amount, CurrencyUnit currencyUnit) {
    Objects.requireNonNull(amount, "Amount must not be null.");
    final CurrencyUnit amountCurrency = amount.getCurrency();
    if (!(currencyUnit.getCurrencyCode().equals(amountCurrency.getCurrencyCode()))) {
        throw new MonetaryException("Currency mismatch: " + currencyUnit + '/' + amountCurrency);
    }
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:17,代码来源:MoneyUtils.java


注:本文中的javax.money.MonetaryAmount.getCurrency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。