java.util.Currency.getNumericCode()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中java.util.Currency.getNumericCode()方法的一些代码示例,展示了Currency.getNumericCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Currency.getNumericCode()方法的具体详情如下:
包路径:java.util.Currency
类名称:Currency
方法名:getNumericCode

Currency.getNumericCode介绍

[英]Returns the ISO 4217 numeric code of this currency.
[中]返回此货币的ISO 4217数字代码。

代码示例

代码示例来源:origin: org.javamoney.moneta/moneta-core

/**
 * Gets a numeric currency code. Within the ISO-4217 name space, this equals
 * to the ISO numeric code. In other currency name spaces this number may be
 * different, or even undefined (-1).
 * <p>
 * The numeric code is an optional alternative to the standard currency
 * code. If defined, the numeric code is required to be unique.
 * <p>
 * This method matches the API of <type>java.util.Currency</type>.
 *
 * @return the numeric currency code
 * @see CurrencyUnit#getNumericCode()
 */
public int getNumericCode() {
  return baseCurrency.getNumericCode();
}

代码示例来源:origin: stackoverflow.com

public static Currency getCurrencyInstance(int numericCode) {
  Set<Currency> currencies = Currency.getAvailableCurrencies();
  for (Currency currency : currencies) {
    if (currency.getNumericCode() == numericCode) {
      return currency;
    }
  }
  throw new IllegalArgumentException("Currency with numeric code "  + numericCode + " not found");
}

代码示例来源:origin: org.javamoney.moneta/moneta-core

private List<CurrencyUnit> getCurrencyUnits(int numCode) {
  List<CurrencyUnit> result = new ArrayList<>();
  for(Currency currency: Currency.getAvailableCurrencies()){
    if(currency.getNumericCode()==numCode){
      result.add(CACHED.get(currency.getCurrencyCode()));
    }
  }
  return result;
}

代码示例来源:origin: stackoverflow.com

public static Currency getCurrencyByCode(int code) {
  for(Currency currency : Currency.getAvailableCurrencies()) {
    if(currency.getNumericCode() == code) {
      return currency;
    }
  }
  throw new IllegalArgumentException("Unkown currency code: " + code);
}

代码示例来源:origin: stackoverflow.com

public static Currency getByCode(int code) {
  for(Currency c : Currency.getAvailableCurrencies()) {
    if(c.getNumericCode() == code) {
      return c;
    }
  }
  throw new IllegalArgumentException("Unkown currency code: " + code);
}

代码示例来源:origin: stackoverflow.com

Currency curr = Currency.getInstance("AZM");
 System.out.println(curr.getCurrencyCode()); // AZM
 System.out.println(curr.getNumericCode());  // 31
 System.out.println(curr.getDisplayName());  // Azerbaijani Manat (1993-2006)

代码示例来源:origin: stackoverflow.com

Set<Currency> avail = Currency.getAvailableCurrencies();
 for (Currency next : avail) {
   System.out.println("----------------------------------------");
   System.out.println("displayName="+next.getDisplayName());
   System.out.println("currencyCode="+next.getCurrencyCode());
   System.out.println("numericCode="+next.getNumericCode());
   System.out.println("symbol="+next.getSymbol());
   System.out.println("toString="+next.toString());
   System.out.println("----------------------------------------");
 }

代码示例来源:origin: jpos/jPOS

private static void addJavaCurrencies()
{
  List<java.util.Currency> currencies = java.util.Currency.getAvailableCurrencies()
      .stream()
      .sorted(Comparator.comparing(java.util.Currency::getCurrencyCode))
      .collect(Collectors.toList());
  for (java.util.Currency sc : currencies)
  {
    try
    {
      addCurrency(sc.getCurrencyCode().toUpperCase(),
            ISOUtil.zeropad(Integer.toString(sc.getNumericCode()), 3),
            sc.getDefaultFractionDigits());
    }
    catch (ISOException ignored)
    {
    }
  }
}

代码示例来源:origin: org.apache.tamaya/tamaya-java7-core

if (currency.getNumericCode() == numCode) {
  return currency;

代码示例来源:origin: org.apache.tamaya/tamaya-core

if (currency.getNumericCode() == numCode) {
  return currency;

代码示例来源:origin: org.javamoney/javamoney-tck

"currency code: " +
        currency.getCurrencyCode() + ", expected: " +
        Currency.getInstance(currency.getCurrencyCode()).getNumericCode() +
        ", found: " + unit.getNumericCode(),
    Currency.getInstance(currency.getCurrencyCode()).getNumericCode(), unit.getNumericCode());
AssertJUnit.assertEquals(
    "Section 4.2.7: Invalid default fraction unit returned from [Monetary#igetCurrency" +

代码示例来源:origin: org.javamoney/javamoney-tck

/**
 * Test that JDK currencies returned match the values of corresponding JDK Currency (code, numeric code,
 * default fraction digits).
 */
@SpecAssertion(section = "4.2.1", id = "421-A4")
@Test(description = "4.2.1 Test currencies provided have correct default fraction digits and numeric code.")
public void testISOCodes() {
  for (Currency currency : Currency.getAvailableCurrencies()) {
    CurrencyUnit unit = Monetary.getCurrency(currency.getCurrencyCode());
    AssertJUnit.assertEquals(currency.getCurrencyCode(), unit.getCurrencyCode());
    AssertJUnit.assertEquals(currency.getDefaultFractionDigits(), unit.getDefaultFractionDigits());
    AssertJUnit.assertEquals(currency.getNumericCode(), unit.getNumericCode());
  }
}

代码示例来源:origin: org.javamoney/javamoney-tck

"Section 4.2.7: Invalid numeric code returned from [Monetary#igetCurrency(Locale)] for " +
        "locale: " +
        locale + ", expected: " + Currency.getInstance(locale).getNumericCode() +
        ", found: " + requiredCurrency.getNumericCode(),
    Currency.getInstance(locale).getNumericCode(), requiredCurrency.getNumericCode());
AssertJUnit.assertEquals(
    "Section 4.2.7: Invalid default fraction unit returned from [Monetary#igetCurrency" +

代码示例来源:origin: jpos/jPOS

@Test
public void testAllISOCurrenciesIncluded() {
  Set<java.util.Currency> currencies = java.util.Currency.getAvailableCurrencies();
  StringBuilder msg = new StringBuilder();
  for (java.util.Currency sc : currencies) {
    try {
      if (sc.getDefaultFractionDigits() < 0) continue; // Skip pseudo currencies
      int currencyCode = sc.getNumericCode();
      
      Currency currencyByCode = ISOCurrency.getCurrency(currencyCode);
              
      assertEquals("jPOS currency does not match decimals", sc.getDefaultFractionDigits(), currencyByCode.getDecimals());
    } catch (Throwable ignored) {
      msg.append(sc.getCurrencyCode().toUpperCase() + "=" + 
          ISOUtil.zeropad(sc.getNumericCode(), 3) + " " +  sc.getDefaultFractionDigits() + 
          " //" + sc.getDisplayName() + ":" + ignored.getMessage() + "\n");
    }
  }
  assertEquals(msg.toString(), msg.length(), 0);
}

相关文章