List of usage examples for java.util Currency getInstance
public static Currency getInstance(Locale locale)
Currency
instance for the country of the given locale. From source file:com.prowidesoftware.swift.utils.IsoUtils.java
private IsoUtils() { /*//w w w . j a v a2s. c om * load currencies from all available locale instances * * TODO This should be replaced by Currency.getAvailableCurrencies() once Prowide Core in migrated to Java7 */ currencies = new HashSet<String>(); for (Locale locale : Locale.getAvailableLocales()) { try { String val = Currency.getInstance(locale).getCurrencyCode(); if (!currencies.contains(val)) { currencies.add(val); } } catch (Exception e) { log.log(Level.FINEST, "error loading currencies from locale " + locale, e); } } countries = new HashSet<String>(Arrays.asList(Locale.getISOCountries())); // Add country code for Kosovo, not yet in ISO but used by SWIFT addCountry("XK"); }
From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java
public static String getIso(Activity context) { SharedPreferences settingsToGet = context.getSharedPreferences(BRConstants.PREFS_NAME, 0); return settingsToGet.getString(BRConstants.CURRENT_CURRENCY, Currency.getInstance(Locale.getDefault()).getCurrencyCode()); }
From source file:com.erudika.para.i18n.CurrencyUtils.java
private CurrencyUtils() { Locale[] locales = Locale.getAvailableLocales(); try {/* www . jav a2s . co m*/ for (Locale l : locales) { if (!StringUtils.isBlank(l.getCountry())) { COUNTRY_TO_LOCALE_MAP.put(l.getCountry(), l); Currency c = Currency.getInstance(l); if (c != null) { CURRENCY_TO_LOCALE_MAP.put(c.getCurrencyCode(), l); CURRENCIES_MAP.put(c.getCurrencyCode(), getCurrencyName(c.getCurrencyCode(), Locale.US).concat(" ").concat(c.getSymbol(l))); } } } // overwrite main locales CURRENCY_TO_LOCALE_MAP.put("USD", Locale.US); CURRENCY_TO_LOCALE_MAP.put("EUR", Locale.FRANCE); } catch (Exception e) { logger.error(null, e); } }
From source file:org.yestech.lib.currency.Money.java
public Money(double amount, Locale locale) { if (amount < 0) { throw new CurrencyException("money amount must be a positive number"); }// ww w . jav a2 s .c o m if (locale == null) { throw new CurrencyException("can't have a null locale"); } this.amount = new BigDecimal(amount); this.locale = locale; this.curreny = Currency.getInstance(locale); }
From source file:ch.silviowangler.dox.domain.AmountOfMoney.java
public AmountOfMoney(String value) { notNull(value, "Value must not be null"); hasText(value, "Value must not be blank"); logger.trace("Value is '{}'", value); final String trimmedValue = value.trim(); logger.trace("Trimmed value is '{}'", trimmedValue); final String clearedWhitespaces = trimmedValue.replaceAll(" +", " "); logger.trace("Cleared value is '{}'", trimmedValue); String[] args = clearedWhitespaces.split(" "); isTrue(args.length == 2,/* www .j a v a 2s .c om*/ "Please provide currency code and amount. E.g. CHF 1250.50. Your value is " + value); logger.trace("Arg currency {}, arg amount {}", args[0], args[1]); this.currency = Currency.getInstance(args[0]); this.amount = new BigDecimal(args[1]); }
From source file:org.broadleafcommerce.vendor.CyberSourceTaxServiceTest.java
@Test(groups = { "testSuccessfulCyberSourceTax" }) @Rollback(false)//from w ww . j a va2s. c o m public void testSuccessfulCyberSourceTax() throws Exception { if (serviceManager.getMerchantId().equals("?")) { return; } System.out.println("***Initiating testSuccessfulCyberSourceTax***"); CyberSourceTaxRequest taxRequest = new CyberSourceTaxRequest(); taxRequest.setCurrency(Currency.getInstance(Locale.US).getCurrencyCode()); taxRequest.setNexus("CA"); taxRequest.setOrderAcceptancePostalCode("94043"); //taxRequest.setOrderOriginPostalCode("94043"); CyberSourceBillingRequest billingRequest = new CyberSourceBillingRequest(); billingRequest.setCity("Mountain View"); billingRequest.setPostalCode("94043"); billingRequest.setState("CA"); billingRequest.setStreet1("1295 Charleston Road"); billingRequest.setCountry("US"); taxRequest.setBillingRequest(billingRequest); CyberSourceTaxItemRequest itemRequest1 = new CyberSourceTaxItemRequest(); itemRequest1.setDescription("First Item"); itemRequest1.setQuantity(2L); itemRequest1.setShortDescription("firstItem"); itemRequest1.setUnitPrice(new Money(12.34)); taxRequest.getItemRequests().add(itemRequest1); CyberSourceTaxService service = (CyberSourceTaxService) serviceManager.getValidService(taxRequest); ((ServiceResponseCacheable) service).clearCache(); CyberSourceTaxResponse response = (CyberSourceTaxResponse) service.process(taxRequest); assert (response.getReasonCode().intValue() == 100); assert (!response.getRequestToken().equals("from-cache")); Money totalTaxAmount = response.getItemResponses()[0].getTotalTaxAmount(); assert (totalTaxAmount != null && totalTaxAmount.greaterThan(new Money(0D))); //confirm that we used the cache CyberSourceTaxResponse response2 = (CyberSourceTaxResponse) service.process(taxRequest); assert (response2.getReasonCode().intValue() == 100); assert (response2.getRequestToken().equals("from-cache")); Money totalTaxAmount2 = response2.getItemResponses()[0].getTotalTaxAmount(); assert (totalTaxAmount2 != null && totalTaxAmount2.greaterThan(new Money(0D))); assert (totalTaxAmount.equals(totalTaxAmount2)); }
From source file:com.trenako.entities.Money.java
/** * Creates a new {@code Money} using the currency from * the provided Locale.//from w w w . j av a 2 s . c om * * @param value the {@code Money} value * @param locale the currency locale */ public Money(int value, Locale locale) { this(value, Currency.getInstance(locale).getCurrencyCode()); }
From source file:com.squarespace.template.plugins.platform.i18n.MoneyFormatter.java
private static Currency getCurrency(JsonNode node) { String currencyStr = StringUtils.trimToNull(node.path(CURRENCY_FIELD_NAME).asText()); if (currencyStr == null) { return DEFAULT_CURRENCY; }//from w w w . j a va2 s .c o m return Currency.getInstance(currencyStr); }
From source file:com.ibuildapp.romanblack.CataloguePlugin.utils.Utils.java
/** * compution currency positon/*from w w w . j av a 2s .c o m*/ */ public static String currencyToPosition(String currencyStr, float price) { try { Locale locale = Locale.getDefault(); Currency currency = Currency.getInstance(currencyStr); java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(locale); format.setCurrency(currency); return format.format(price); } catch (Exception e) { return ""; } }
From source file:com.pamarin.income.controller.ChartExpensesCtrl.java
private String getCurrencySymbol() { return Currency.getInstance(SecurityUtils.getUser().getSettings().getCurrencyCode()).getSymbol(); }