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

The following examples show how to use com.ibm.icu.util.Currency#getInstance() . 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: FormatCurrencyNumPattern.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the default number of fraction digits that should be displayed
 * for the default currency for given locale.
 * 
 * @param locale
 * @return
 */
public static int getDefaultFractionDigits( ULocale locale )
{
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	Currency currency = Currency.getInstance( locale );
	if ( currency != null )
	{
		return currency.getDefaultFractionDigits( );
	}

	return 2;
}
 
Example 2
Source File: NumberFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the currency in effect for this formatter.  Subclasses
 * should override this method as needed.  Unlike getCurrency(),
 * this method should never return null.
 * @return a non-null Currency
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
protected Currency getEffectiveCurrency() {
    Currency c = getCurrency();
    if (c == null) {
        ULocale uloc = getLocale(ULocale.VALID_LOCALE);
        if (uloc == null) {
            uloc = ULocale.getDefault(Category.FORMAT);
        }
        c = Currency.getInstance(uloc);
    }
    return c;
}
 
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: DecimalFormatSymbols.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the symbols from the locale data.
 */
private void initialize( ULocale locale ) {
    this.requestedLocale = locale.toLocale();
    this.ulocale = locale;
    CacheData data = cachedLocaleData.getInstance(locale, null /* unused */);
    setLocale(data.validLocale, data.validLocale);
    setDigitStrings(data.digits);
    String[] numberElements = data.numberElements;

    // Copy data from the numberElements map into instance fields
    setDecimalSeparatorString(numberElements[0]);
    setGroupingSeparatorString(numberElements[1]);

    // See CLDR #9781
    // assert numberElements[2].length() == 1;
    patternSeparator = numberElements[2].charAt(0);

    setPercentString(numberElements[3]);
    setMinusSignString(numberElements[4]);
    setPlusSignString(numberElements[5]);
    setExponentSeparator(numberElements[6]);
    setPerMillString(numberElements[7]);
    setInfinity(numberElements[8]);
    setNaN(numberElements[9]);
    setMonetaryDecimalSeparatorString(numberElements[10]);
    setMonetaryGroupingSeparatorString(numberElements[11]);
    setExponentMultiplicationSign(numberElements[12]);

    digit = DecimalFormat.PATTERN_DIGIT;  // Localized pattern character no longer in CLDR
    padEscape = DecimalFormat.PATTERN_PAD_ESCAPE;
    sigDigit  = DecimalFormat.PATTERN_SIGNIFICANT_DIGIT;


    CurrencyDisplayInfo info = CurrencyData.provider.getInstance(locale, true);

    // Obtain currency data from the currency API.  This is strictly
    // for backward compatibility; we don't use DecimalFormatSymbols
    // for currency data anymore.
    currency = Currency.getInstance(locale);
    if (currency != null) {
        intlCurrencySymbol = currency.getCurrencyCode();
        currencySymbol = currency.getName(locale, Currency.SYMBOL_NAME, null);
        CurrencyFormatInfo fmtInfo = info.getFormatInfo(intlCurrencySymbol);
        if (fmtInfo != null) {
            currencyPattern = fmtInfo.currencyPattern;
            setMonetaryDecimalSeparatorString(fmtInfo.monetarySeparator);
            setMonetaryGroupingSeparatorString(fmtInfo.monetaryGroupingSeparator);
        }
    } else {
        intlCurrencySymbol = "XXX";
        currencySymbol = "\u00A4"; // 'OX' currency symbol
    }


    // Get currency spacing data.
    initSpacingInfo(info.getSpacingInfo());
}
 
Example 5
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;
}