當前位置: 首頁>>代碼示例>>Java>>正文


Java Currency類代碼示例

本文整理匯總了Java中java.util.Currency的典型用法代碼示例。如果您正苦於以下問題:Java Currency類的具體用法?Java Currency怎麽用?Java Currency使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Currency類屬於java.util包,在下文中一共展示了Currency類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_for_issue

import java.util.Currency; //導入依賴的package包/類
public void test_for_issue() throws Exception {
    Money money = new Money();
    money.currency = Currency.getInstance("CNY");
    money.amount = new BigDecimal("10.03");

    String json = JSON.toJSONString(money);

    Money moneyBack = JSON.parseObject(json, Money.class);
    Assert.assertEquals(money.currency, moneyBack.currency);
    Assert.assertEquals(money.amount, moneyBack.amount);

    JSONObject jsonObject = JSON.parseObject(json);
    Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
    Assert.assertEquals(money.currency, moneyCast.currency);
    Assert.assertEquals(money.amount, moneyCast.amount);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:Bug_for_issue_349.java

示例2: transformLocale

import java.util.Currency; //導入依賴的package包/類
private ArrayList<Currency> transformLocale(Locale[] locales) {
    ArrayList<Currency> currencies = new ArrayList<>();

    for (Locale locale : locales) {
        try {
            Currency currency = Currency.getInstance(locale);

            if (!currencies.contains(currency)) {
                currencies.add(currency);
            }

        } catch (IllegalArgumentException e) {
            continue;
        }
    }

    return currencies;
}
 
開發者ID:WGPlaner,項目名稱:wg_planer,代碼行數:19,代碼來源:GroupSettingsActivity.java

示例3: test_0

import java.util.Currency; //導入依賴的package包/類
public void test_0() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.put(Currency.class
            , config.createJavaBeanSerializer(Currency.class));

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("value", Currency.getInstance("CNY"));

    String text = JSON.toJSONString(jsonObject, config);
    System.out.println(text);
    String str1 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"symbol\":\"CNY\"}}";
    String str2 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"人民幣\",\"symbol\":\"¥\"}}";
    String str3 = "{\"value\":{\"currencyCode\":\"CNY\",\"displayName\":\"Chinese Yuan\",\"numericCodeAsString\":\"156\",\"symbol\":\"CN¥\"}}";
    assertTrue(text.equals(str1)
            || text.equals(str2)
            || text.equals(str3));

    Currency currency = JSON.parseObject(text, VO.class).value;

    assertSame(Currency.getInstance("CNY"), currency);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:CurrencyTest5.java

示例4: types

import java.util.Currency; //導入依賴的package包/類
@DataProvider(name = "types")
public Object[][] types() {
    return new Object[][] {
        { Object.class },
        { Boolean.class },
        { Integer.class },
        { Long.class },
        { Double.class },
        { String.class },
        { Month.class },
        { Currency.class },
        { Date.class },
        { LocalDate.class },
        { LocalTime.class },
        { LocalDateTime.class },
        { ZonedDateTime.class }
    };
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:19,代碼來源:ArrayBuilderTests.java

示例5: _setCurrencyInformation

import java.util.Currency; //導入依賴的package包/類
private void _setCurrencyInformation(
  RequestContext context,
  DecimalFormatSymbols symbols)
{
  String currencyCode = _getCurrencyCode(context);

  // currencyCode is set we honour currency code.
  if (currencyCode != null)
  {
    symbols.setCurrency(Currency.getInstance(currencyCode));
    return;
  }

  if (getCurrencySymbol() != null)
  {
    symbols.setCurrencySymbol(getCurrencySymbol());

     // Loggin at level INFO - shows up by default - so use fine.
    _LOG.fine("Using currency symbol as currecny code evaluates to null");
  }
  // currency symbol will now default based on the locale.
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:23,代碼來源:NumberConverter.java

示例6: onViewCreated

import java.util.Currency; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    btn_find = (Button) view.findViewById(R.id.btn_find);
    et_location_name = (EditText) view.findViewById(R.id.et_location_name);
    et_country_code = (EditText) view.findViewById(R.id.et_country_code);
    et_countyISO = (EditText) view.findViewById(R.id.et_countyISO);
    et_currencyCode = (EditText) view.findViewById(R.id.et_currencyCode);
    tv_currencySymbol = (TextView) view.findViewById(R.id.tv_currencySymbol);
    tv_currencyDisplayName = (TextView) view.findViewById(R.id.tv_currencyDisplayName);
    tv_currencyCode = (TextView) view.findViewById(R.id.tv_currencyCode);
    tv_fractionDigits = (TextView) view.findViewById(R.id.tv_fractionDigits);
    tv_numericCode = (TextView) view.findViewById(R.id.tv_numericCode);
    tv_noDataFound = (TextView) view.findViewById(R.id.tv_noDataFound);
    fl_bottomContents = (FrameLayout) view.findViewById(R.id.fl_bottomContents);

    availableCurrenciesSet = Currency.getAvailableCurrencies();
    currencyList = new ArrayList<>(availableCurrenciesSet);
    btn_find.setOnClickListener(this);
}
 
開發者ID:Fenscode,項目名稱:FindCurrencyExa,代碼行數:22,代碼來源:MainFragment.java

示例7: getExchangeRateForCurrency

import java.util.Currency; //導入依賴的package包/類
@Override
public double getExchangeRateForCurrency(Currency currency) {
    logger.trace(currency.getCurrencyCode());
    NodeList list = this.exchangeRates.getElementsByTagName("Rate");
    for(int i=0;i<list.getLength();i++)
    {
        Node n = list.item(i);
        if(n.getNodeType() == Node.ELEMENT_NODE)
        {
            Element e = (Element) n;
            logger.trace(e.getAttribute("curr") + ": " + Double.parseDouble(e.getTextContent().replace(",",".")) / Double.parseDouble(e.getAttribute("unit")));
            if(e.getAttribute("curr").equals(currency.getCurrencyCode())){
                return Double.parseDouble(e.getTextContent().replace(",",".")) / Double.parseDouble(e.getAttribute("unit"));
            }
        }
    }
    return -1.0;
}
 
開發者ID:Chrams,項目名稱:openfleet,代碼行數:19,代碼來源:MNBExchangeService.java

示例8: createSubUsingUSD

import java.util.Currency; //導入依賴的package包/類
/**
 * Creates a subscription that is based on a price model using USD as
 * currency.
 * 
 * @param modTime
 *            The time the change to use USD should be performed at.
 * @throws Exception
 */
private void createSubUsingUSD(final long modTime) throws Exception {
    runTX(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            SupportedCurrency sc = new SupportedCurrency();
            sc.setCurrency(Currency.getInstance("USD"));
            dm.persist(sc);

            Subscription subNew = Subscriptions.createSubscription(dm,
                    Scenario.getCustomer().getOrganizationId(),
                    Scenario.getProduct().getProductId(), "SubUSD",
                    Scenario.getSupplier());
            dm.flush();
            subNew.setHistoryModificationTime(Long.valueOf(modTime));
            PriceModel priceModel = subNew.getPriceModel();
            priceModel.setCurrency(sc);
            priceModel.setHistoryModificationTime(Long.valueOf(modTime));

            return null;
        }
    });
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:31,代碼來源:BillingDataRetrievalServiceBeanCurrencyIT.java

示例9: main

import java.util.Currency; //導入依賴的package包/類
public static void main(String[] args) {

        String numericCode = Currency.getInstance("AFA").getNumericCodeAsString();
        if (!numericCode.equals("004")) { //should return "004" (a 3 digit string)
           throw new RuntimeException("[Expected 004, "
                + "found "+numericCode+" for AFA]");
        }

        numericCode = Currency.getInstance("AUD").getNumericCodeAsString();
        if (!numericCode.equals("036")) { //should return "036" (a 3 digit string)
            throw new RuntimeException("[Expected 036, "
                + "found "+numericCode+" for AUD]");
        }

        numericCode = Currency.getInstance("USD").getNumericCodeAsString();
        if (!numericCode.equals("840")) {// should return "840" (a 3 digit string)
            throw new RuntimeException("[Expected 840, "
                + "found "+numericCode+" for USD]");
        }

    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:Bug8154295.java

示例10: getSupportedCurrencies

import java.util.Currency; //導入依賴的package包/類
public static List<Currency> getSupportedCurrencies() {
    checkPropertiesAreLoaded();

    List<Currency> currencies = new ArrayList<>();
    for (String currencyString : properties.stringPropertyNames())
        currencies.add(Currency.getInstance(currencyString));

    Collections.sort(currencies, new Comparator<Currency>() {
        @Override
        public int compare(Currency c1, Currency c2) {
            return c1.getCurrencyCode().compareTo(c2.getCurrencyCode());
        }
    });

    return currencies;
}
 
開發者ID:piskula,項目名稱:FuelUp,代碼行數:17,代碼來源:CurrencyUtil.java

示例11: createIlegalArgumentsException

import java.util.Currency; //導入依賴的package包/類
private IllegalArgumentException createIlegalArgumentsException(final Currency accountCurrency,
        final ForexSymbol tradedSymbol) {
    return new IllegalArgumentException("Should calculate the value of a single pipette of the symbol \""
            + tradedSymbol + "\" in \"" + accountCurrency
            + "\" and requiering therefor the the exchange rate from \"" + tradedSymbol.getQuoteCurrency()
            + "\" to \"" + accountCurrency + "\" but that exchange rate was not available.");
}
 
開發者ID:rbi,項目名稱:trading4j,代碼行數:8,代碼來源:PipetteValueCalculator.java

示例12: testJson

import java.util.Currency; //導入依賴的package包/類
public void testJson() throws Exception {
    Money money = new Money();
    money.currency = Currency.getInstance("CNY");
    money.amount = new BigDecimal("10.03");

    String json = JSON.toJSONString(money);
    System.out.println("json = " + json);

    Money moneyBack = JSON.parseObject(json, Money.class);
    System.out.println("money = " + moneyBack);

    JSONObject jsonObject = JSON.parseObject(json);
    Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
    System.out.printf("money = " + moneyCast);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:CurrencyTest3.java

示例13: setCurrency

import java.util.Currency; //導入依賴的package包/類
/**
 * Set the currency symbol for the edit text. (Default is US Dollar $).
 * @param currency the currency object of new symbol. (Defaul is Locale.US)
 */
public void setCurrency(Currency currency)
{
    setCurrency(currency.getSymbol());
}
 
開發者ID:wajahatkarim3,項目名稱:EasyMoney-Widgets,代碼行數:9,代碼來源:EasyMoneyEditText.java

示例14: readObject

import java.util.Currency; //導入依賴的package包/類
/**
 * Reads the default serializable fields, provides default values for objects
 * in older serial versions, and initializes non-serializable fields.
 * If <code>serialVersionOnStream</code>
 * is less than 1, initializes <code>monetarySeparator</code> to be
 * the same as <code>decimalSeparator</code> and <code>exponential</code>
 * to be 'E'.
 * If <code>serialVersionOnStream</code> is less than 2,
 * initializes <code>locale</code>to the root locale, and initializes
 * If <code>serialVersionOnStream</code> is less than 3, it initializes
 * <code>exponentialSeparator</code> using <code>exponential</code>.
 * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
 * default serialization will work properly if this object is streamed out again.
 * Initializes the currency from the intlCurrencySymbol field.
 *
 * @since  1.1.6
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (serialVersionOnStream < 1) {
        // Didn't have monetarySeparator or exponential field;
        // use defaults.
        monetarySeparator = decimalSeparator;
        exponential       = 'E';
    }
    if (serialVersionOnStream < 2) {
        // didn't have locale; use root locale
        locale = Locale.ROOT;
    }
    if (serialVersionOnStream < 3) {
        // didn't have exponentialSeparator. Create one using exponential
        exponentialSeparator = Character.toString(exponential);
    }
    serialVersionOnStream = currentSerialVersion;

    if (intlCurrencySymbol != null) {
        try {
             currency = Currency.getInstance(intlCurrencySymbol);
        } catch (IllegalArgumentException e) {
        }
        currencyInitialized = true;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:45,代碼來源:DecimalFormatSymbols.java

示例15: buildFromWebRequest

import java.util.Currency; //導入依賴的package包/類
/**
 * Takes the parameters from the {@link org.springframework.web.context.request.WebRequest} and parses into the new {@link com.markbudai.openfleet.model.TransferCost} object by its setter methods.
 * @param request the {@link org.springframework.web.context.request.WebRequest} containing parameters for the new {@link com.markbudai.openfleet.model.TransferCost} object.
 * @return the parsed  {@link com.markbudai.openfleet.model.TransferCost} object.
 * @exception com.markbudai.openfleet.exception.EmptyParameterException if any parameter is empty.
 */
public static TransferCost buildFromWebRequest(WebRequest request){
    TransferCost t = new TransferCost();
    logger.trace("Starting builder.");
    logger.debug("start parsing data");
    if(request.getParameter("amount").isEmpty()){
        logger.debug(request.getParameter("amount"));
        throw new EmptyParameterException("amount");
    }
    logger.debug("amount");
    t.setAmount(Long.parseLong(request.getParameter("amount")));
    if(request.getParameter("costDescription").isEmpty()){
        throw new EmptyParameterException("costDescription");
    }
    logger.debug("costDescription");
    t.setCostDescription(request.getParameter("costDescription"));
    if(request.getParameter("currency").isEmpty()){
        throw new EmptyParameterException("currency");
    }
    logger.debug("currency");
    t.setCurrency(Currency.getInstance(request.getParameter("currency")));
    if(request.getParameter("date").isEmpty()){
        throw new EmptyParameterException("date");
    }
    logger.debug("date");
    t.setDate(LocalDate.parse(request.getParameter("date")));

    return t;
}
 
開發者ID:Chrams,項目名稱:openfleet,代碼行數:35,代碼來源:TransferCostBuilder.java


注:本文中的java.util.Currency類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。