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


Java CurrencyUnit.getDefaultFractionDigits方法代码示例

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


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

示例1: main

import javax.money.CurrencyUnit; //导入方法依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit currencyUnit = Monetary.getCurrency(Locale.US);
    String currencyCode = currencyUnit.getCurrencyCode();//USD
    int numericCurrencyCode = currencyUnit.getNumericCode();//840
    int fractionDigits = currencyUnit.getDefaultFractionDigits();//2

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

示例2: main

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

        CurrencyUnit currencyUnit = Monetary.getCurrency("BRL");
        String currencyCode = currencyUnit.getCurrencyCode();//BRL
        int numericCurrencyCode = currencyUnit.getNumericCode();//2
        int fractionDigits = currencyUnit.getDefaultFractionDigits();//986

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

示例3: apply

import javax.money.CurrencyUnit; //导入方法依赖的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: testGetRoundingCurrencyUnit

import javax.money.CurrencyUnit; //导入方法依赖的package包/类
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(javax.money.CurrencyUnit, String...)}
 * .
 */
@Test
public void testGetRoundingCurrencyUnit() {
    MonetaryAmount[] samples = new MonetaryAmount[]{
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("0.0000000001"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("1.00000000000023")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.1123442323"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.50000000000"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("-1.000000003"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("-1.100232876532876389")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF")
                    .setNumber(new BigDecimal("-1.500000000000")).create()};
    for (MonetaryAmount sample : samples) {
        for (Currency currency : Currency.getAvailableCurrencies()) {
            CurrencyUnit cur = Monetary.getCurrency(currency.getCurrencyCode());
            // Omit test roundings, which are for testing only...
            if ("XXX".equals(cur.getCurrencyCode())) {
                continue;
            } else if ("CHF".equals(cur.getCurrencyCode())) {
                continue;
            }
            MonetaryOperator rounding = Monetary.getRounding(cur);
            BigDecimal dec = sample.getNumber().numberValue(BigDecimal.class);
            BigDecimal expected;
            if (cur.getDefaultFractionDigits() < 0) {
                expected = dec.setScale(0, RoundingMode.HALF_UP);
            } else {
                expected = dec.setScale(cur.getDefaultFractionDigits(), RoundingMode.HALF_UP);
            }
            MonetaryAmount r = sample.with(rounding);
            assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(expected).create(),
                    r, "Rouding for: " + sample);
        }
    }
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:44,代码来源:MonetaryRoundingsTest.java

示例5: queryFrom

import javax.money.CurrencyUnit; //导入方法依赖的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

示例6: DefaultRounding

import javax.money.CurrencyUnit; //导入方法依赖的package包/类
/**
 * Creates an {@link DefaultRounding} for rounding {@link javax.money.MonetaryAmount}
 * instances given a currency.
 *
 * @param currency The currency, which determines the required precision. As
 *                 {@link RoundingMode}, by default, {@link RoundingMode#HALF_UP}
 *                 is used.
 */
DefaultRounding(CurrencyUnit currency, RoundingMode roundingMode) {
    this(currency.getDefaultFractionDigits(), roundingMode);
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:DefaultRounding.java

示例7: DefaultCashRounding

import javax.money.CurrencyUnit; //导入方法依赖的package包/类
/**
 * Creates an {@link DefaultCashRounding} for rounding
 * {@link MonetaryAmount} instances given a currency.
 *
 * @param currency The currency, which determines the required precision. As
 *                 {@link RoundingMode}, by default, {@link RoundingMode#HALF_UP}
 *                 is used.
 */
DefaultCashRounding(CurrencyUnit currency, RoundingMode roundingMode, int minimalMinors) {
    this(currency.getDefaultFractionDigits(), roundingMode, minimalMinors);
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:12,代码来源:DefaultCashRounding.java


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