本文整理汇总了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
}
示例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
}
示例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();
}
示例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);
}
}
}
示例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();
}
示例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);
}
示例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);
}