本文整理了Java中java.util.Currency.getDefaultFractionDigits()
方法的一些代码示例,展示了Currency.getDefaultFractionDigits()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Currency.getDefaultFractionDigits()
方法的具体详情如下:
包路径:java.util.Currency
类名称:Currency
方法名:getDefaultFractionDigits
[英]Returns the default number of fraction digits for this currency. For instance, the default number of fraction digits for the US dollar is 2 because there are 100 US cents in a US dollar. For the Japanese Yen, the number is 0 because coins smaller than 1 Yen became invalid in 1953. In the case of pseudo-currencies, such as IMF Special Drawing Rights, -1 is returned.
[中]返回此货币的默认小数位数。例如,美元的默认分数位数为2,因为美元中有100美分。对于日元,这个数字是0,因为小于1日元的硬币在1953年失效。对于伪货币,如IMF特别提款权,返回-1。
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public static int getScaleForCurrency(Currency currency) {
if (currency != null) {
return currency.getDefaultFractionDigits();
} else {
return DEFAULT_SCALE;
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
public int getDefaultFractionDigits() {
return value.getDefaultFractionDigits();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)
*
* @param blCurrency
* @return
*/
public static Money getUnitAmount(BroadleafCurrency blCurrency) {
Currency currency = getCurrency(blCurrency);
BigDecimal divisor = new BigDecimal(Math.pow(10, currency.getDefaultFractionDigits()));
BigDecimal unitAmount = new BigDecimal("1").divide(divisor);
return new Money(unitAmount, currency);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Returns the unit amount (e.g. .01 for US and all other 2 decimal currencies)
*
* @param difference
* @return
*/
public static Money getUnitAmount(Money difference) {
Currency currency = BroadleafCurrencyUtils.getCurrency(difference);
BigDecimal divisor = new BigDecimal(Math.pow(10, currency.getDefaultFractionDigits()));
BigDecimal unitAmount = new BigDecimal("1").divide(divisor);
if (difference.lessThan(BigDecimal.ZERO)) {
unitAmount = unitAmount.negate();
}
return new Money(unitAmount, currency);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public long countNumberOfUnits(Money difference) {
double numUnits = difference.multiply(Math.pow(10, difference.getCurrency().getDefaultFractionDigits())).doubleValue();
return Math.round(Math.abs(numUnits));
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Returns the unit amount (e.g. .01 for US)
* @param currency
* @return
*/
public Money getUnitAmount(Money difference) {
Currency currency = difference.getCurrency();
BigDecimal divisor = new BigDecimal(Math.pow(10, currency.getDefaultFractionDigits()));
BigDecimal unitAmount = new BigDecimal("1").divide(divisor);
if (difference.lessThan(BigDecimal.ZERO)) {
unitAmount = unitAmount.negate();
}
return new Money(unitAmount, currency);
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
protected static Money getMoney(Currency currency, float cost) {
int fractionDigits = 2;
if (currency != null)
fractionDigits = currency.getDefaultFractionDigits();
int cents = (int) Math.round(cost * Math.pow(10, fractionDigits));
return new Money(new WrappedCurrency(currency), cents);
}
代码示例来源:origin: stackoverflow.com
this.currency = currency;
this.amount = amount.setScale(currency.getDefaultFractionDigits(), rounding);
代码示例来源:origin: opentripplanner/OpenTripPlanner
fare.addFare(FareType.regular, new WrappedCurrency(currency),
(int) Math.round(totalFare
* Math.pow(10, currency.getDefaultFractionDigits())));
return fare;
代码示例来源:origin: pentaho/pentaho-kettle
conversionMeta.setCurrencySymbol( currencyFormat.getCurrency().getSymbol() );
conversionMeta.setLength( 15 );
int currencyPrecision = currencyFormat.getCurrency().getDefaultFractionDigits();
conversionMeta.setPrecision( currencyPrecision );
代码示例来源:origin: stackoverflow.com
java.util.Currency usd = java.util.Currency.getInstance("USD");
java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(
java.util.Locale.JAPAN);
format.setCurrency(usd);
System.out.println(format.format(23.23));
format.setMaximumFractionDigits(usd.getDefaultFractionDigits());
System.out.println(format.format(23.23));
代码示例来源:origin: stackoverflow.com
public class CurrencyTest {
public static void main(String[] args) throws Exception {
Locale defaultLocale = Locale.getDefault();
displayCurrencyInfoForLocale(defaultLocale);
Locale swedishLocale = new Locale("sv", "SE");
displayCurrencyInfoForLocale(swedishLocale);
}
public static void displayCurrencyInfoForLocale(Locale locale) {
System.out.println("Locale: " + locale.getDisplayName());
Currency currency = Currency.getInstance(locale);
System.out.println("Currency Code: " + currency.getCurrencyCode());
System.out.println("Symbol: " + currency.getSymbol());
System.out.println("Default Fraction Digits: " + currency.getDefaultFractionDigits());
System.out.println();
}
}
代码示例来源:origin: magro/memcached-session-manager
final Currency currency2 = ( Currency) another;
Assert.assertEquals( currency1.getCurrencyCode(), currency2.getCurrencyCode() );
Assert.assertEquals( currency1.getDefaultFractionDigits(), currency2.getDefaultFractionDigits() );
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.ibm.icu.base
/**
* Returns the number of the number of fraction digits that should
* be displayed for this currency.
* @return a non-negative number of fraction digits to be
* displayed
* @stable ICU 2.2
*/
public int getDefaultFractionDigits() {
return currency.getDefaultFractionDigits();
}
代码示例来源:origin: hiteshsahu/ECommerce-App-Android
Money(BigDecimal amount, Currency currency, RoundingMode rounding) {
this.amount = amount;
this.currency = currency;
this.amount = amount.setScale(currency.getDefaultFractionDigits(),
rounding);
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
public static String formatCurrency(Number number, Locale locale) {
Currency currency = Currency.getInstance(locale);
NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
numberFormat.setCurrency(currency);
numberFormat.setMaximumFractionDigits(currency.getDefaultFractionDigits());
String s = numberFormat.format(number);
s = s.replace(currency.getCurrencyCode(), currency.getSymbol(locale));
return s;
}
代码示例来源:origin: com.aoindustries/ao-lang
/**
* Multiplies with rounding.
*/
public Money multiply(BigDecimal multiplicand, RoundingMode roundingMode) throws ArithmeticException {
int currencyScale = currency.getDefaultFractionDigits();
if(currencyScale==-1) currencyScale = scale; // Use same scale if currency doesn't dictate
return new Money(currency, getValue().multiply(multiplicand).setScale(currencyScale, roundingMode));
}
代码示例来源:origin: org.dasein/dasein-util
public int getFractionValue() {
int frac = getCurrency().getDefaultFractionDigits();
if( frac < 1 ) {
return 0;
}
return Math.round((float)(Math.pow(10, frac-1) * getValue()%1));
}
代码示例来源:origin: BlacKCaT27/CurrencyEditText
private void init(){
this.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
currentLocale = retrieveLocale();
Currency currentCurrency = getCurrencyForLocale(currentLocale);
decimalDigits = currentCurrency.getDefaultFractionDigits();
initCurrencyTextWatcher();
}
代码示例来源:origin: net.sf.tsl2nano/tsl2.nano.descriptor
/**
* formatter for given perhaps historic currency
* @param loc locale
* @param historicCurrencyDate date of currency
* @return formatter
*/
public static NumberFormat getFormat(Locale loc, Date historicCurrencyDate) {
CurrencyUnit currency = getCurrency(loc, historicCurrencyDate);
return getFormat(currency.getCurrencyCode(), currency.getCurrency().getDefaultFractionDigits());
}
内容来源于网络,如有侵权,请联系作者删除!