当前位置: 首页>>代码示例>>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;未经允许,请勿转载。