Java Code Examples for com.ibm.icu.util.Currency#getSymbol()

The following examples show how to use com.ibm.icu.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: ExcelUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static String getCurrencySymbol( ULocale locale )
{
	NumberFormat format = NumberFormat.getCurrencyInstance( locale );
	Currency currency = format.getCurrency( );
	if ( currency != null )
	{
		String symbol = currency.getSymbol( locale );
		if ( symbol.equals( "EUR" ) )
		{
			symbol = "\u20ac"; // "€";
		}
		else if ( symbol.equals( "GBP" ) )
		{
			symbol = "\u00a3"; // "£";
		}
		else if ( symbol.equals( "XXX" ) )
		{
			symbol = "\u00a4"; // "¤";
		}
		return symbol;
	}
	return "$";
}
 
Example 2
Source File: OdsUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static String getCurrencySymbol( ULocale locale )
{
	NumberFormat format = NumberFormat.getCurrencyInstance( locale );
	Currency currency = format.getCurrency( );
	if ( currency != null )
	{
		String symbol = currency.getSymbol( locale );
	if ( symbol.equals( "EUR" ) )
	{
		symbol = "€";
	}
	if ( symbol.equals( "GBP" ) )
	{
		symbol = "£";
	}
	if ( symbol.equals( "XXX" ) )
	{
		symbol = "¤";
	}
	if ( symbol == null )
	{
		symbol = "$";
	}
	return symbol;
	}
	return "$";
}
 
Example 3
Source File: FormatCurrencyNumPattern.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the default currency symbol position for given locale. Returns
 * <code>null</code> if no symbol needed by default.
 * 
 * @param locale
 * @return
 */
public static String getDefaultSymbolPosition( ULocale locale )
{
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	Currency currency = Currency.getInstance( locale );
	if ( currency != null )
	{
		String symbol = currency.getSymbol( );
		if ( symbol == null )
		{
			return null;
		}
		NumberFormat formater = NumberFormat.getCurrencyInstance( locale );
		String result = formater.format( 1 );
		if ( result.endsWith( symbol ) )
		{
			return FormatNumberPattern.SYMBOL_POSITION_AFTER;
		}
		else
		{
			return FormatNumberPattern.SYMBOL_POSITION_BEFORE;
		}
	}
	return null;
}
 
Example 4
Source File: FormatCurrencyNumPattern.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the if symbol space is used by default for given locale.
 * 
 * @param locale
 * @return
 */
public static boolean getDefaultUsingSymbolSpace( ULocale locale )
{
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	Currency currency = Currency.getInstance( locale );
	if ( currency != null )
	{
		String symbol = currency.getSymbol( );
		if ( symbol == null )
		{
			return false;
		}
		NumberFormat formater = NumberFormat.getCurrencyInstance( locale );
		String result = formater.format( 1 );
		if ( result.endsWith( symbol ) )
		{
			result = result.substring( 0, result.indexOf( symbol ) );

			for ( int i = result.length( ) - 1; i >= 0; i-- )
			{
				if ( UCharacter.isSpaceChar( result.codePointAt( i ) ) )
				{
					return true;
				}
			}
		}
		else
		{
			result = result.substring( result.indexOf( symbol )
					+ symbol.length( ) );

			for ( int i = 0; i < result.length( ); i++ )
			{
				if ( UCharacter.isSpaceChar( result.codePointAt( i ) ) )
				{
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 5
Source File: DecimalFormatSymbols.java    From fitnotifications with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the currency.
 *
 * <p><strong>Note:</strong> ICU does not use the DecimalFormatSymbols for the currency
 * any more.  This API is present for API compatibility only.
 *
 * <p>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</code> is null
 * @see #setCurrencySymbol
 * @see #setInternationalCurrencySymbol
 *
 * @stable ICU 3.4
 */
public void setCurrency(Currency currency) {
    if (currency == null) {
        throw new NullPointerException();
    }
    this.currency = currency;
    intlCurrencySymbol = currency.getCurrencyCode();
    currencySymbol = currency.getSymbol(requestedLocale);
}