Java Code Examples for java.util.Currency#getSymbol()
The following examples show how to use
java.util.Currency#getSymbol() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LegacyMoneyFormatFactory.java From template-compiler with Apache License 2.0 | 5 votes |
/** * Gets currency symbol that has been decided on for Squarespace money design standard. If a standard does not exist * for the currency, this falls back on Java's symbol formatting. * * @param locale locale * @param currency currency * @return the appropriate currency symbol */ private static String getCurrencySymbol(Locale locale, Currency currency) { String currencySymbol = CURRENCY_SYMBOLS.get(currency.getCurrencyCode()); if (currencySymbol == null) { currencySymbol = currency.getSymbol(locale); } return currencySymbol; }
Example 2
Source File: DecimalFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testSetCurrency_symbolOrigin() { Currency currency = Currency.getInstance("CNY"); Locale locale1 = Locale.CHINA; Locale locale2 = Locale.US; String locale1Symbol = currency.getSymbol(locale1); String locale2Symbol = currency.getSymbol(locale2); // This test only works if we can tell where the symbol came from, which requires they are // different across the two locales chosen. assertFalse(locale1Symbol.equals(locale2Symbol)); Locale originalLocale = Locale.getDefault(); try { Locale.setDefault(locale1); String amountDefaultLocale1 = formatArbitraryCurrencyAmountInLocale(currency, locale2); Locale.setDefault(locale2); String amountDefaultLocale2 = formatArbitraryCurrencyAmountInLocale(currency, locale2); // This used to fail because Currency.getSymbol() was used without providing the // format's locale. assertEquals(amountDefaultLocale1, amountDefaultLocale2); } finally { Locale.setDefault(originalLocale); } }
Example 3
Source File: CurrencyTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_nullLocales() { Currency currency = Currency.getInstance(Locale.getDefault()); try { currency.getSymbol(null); fail(); } catch (NullPointerException expected) {} }
Example 4
Source File: CurrencyAmountView.java From bither-android with Apache License 2.0 | 5 votes |
private static String currencySymbol(@Nonnull final String currencyCode) { try { final Currency currency = Currency.getInstance(currencyCode); return currency.getSymbol(); } catch (final IllegalArgumentException x) { return currencyCode; } }
Example 5
Source File: TDecimalFormatSymbols.java From Bytecoder with Apache License 2.0 | 4 votes |
public void setCurrency(Currency currency) { intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 6
Source File: DecimalFormatSymbols.java From j2objc with Apache License 2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); //cachedIcuDFS = null; }
Example 7
Source File: DecimalFormatSymbols.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 8
Source File: DecimalFormatSymbols.java From jdk8u_jdk with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 9
Source File: DecimalFormatSymbols.java From openjdk-8 with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 10
Source File: DecimalFormatSymbols.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 11
Source File: DecimalFormatSymbols.java From hottub with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 12
Source File: DecimalFormatSymbols.java From Java8CN with Apache License 2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 13
Source File: DecimalFormatSymbols.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 14
Source File: DecimalFormatSymbols.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 15
Source File: DecimalFormatSymbols.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @throws NullPointerException if {@code currency} is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } initializeCurrency(locale); this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 16
Source File: DecimalFormatSymbols.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 17
Source File: DecimalFormatSymbols.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 18
Source File: CurrencyToken.java From jsr354-ri with Apache License 2.0 | 3 votes |
/** * This method tries to evaluate the localized symbol name for a * {@link CurrencyUnit}. It uses {@link Currency#getSymbol(Locale)} if the * given currency code maps to a JDK {@link Currency} instance. * <p> * If not found {@code currency.getCurrencyCode()} is returned. * * @param currency The currency, not {@code null} * @return the formatted currency symbol. */ private String getCurrencySymbol(CurrencyUnit currency) { Currency jdkCurrency = getCurrency(currency.getCurrencyCode()); if (Objects.nonNull(jdkCurrency)) { return jdkCurrency.getSymbol(locale); } return currency.getCurrencyCode(); }
Example 19
Source File: DecimalFormatSymbols.java From jdk-1.7-annotated with Apache License 2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }
Example 20
Source File: DecimalFormatSymbols.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Sets the currency of these DecimalFormatSymbols. * This also sets the currency symbol attribute to the currency's symbol * in the DecimalFormatSymbols' locale, and the international currency * symbol attribute to the currency's ISO 4217 currency code. * * @param currency the new currency to be used * @exception NullPointerException if <code>currency</code> is null * @since 1.4 * @see #setCurrencySymbol * @see #setInternationalCurrencySymbol */ public void setCurrency(Currency currency) { if (currency == null) { throw new NullPointerException(); } this.currency = currency; intlCurrencySymbol = currency.getCurrencyCode(); currencySymbol = currency.getSymbol(locale); }