Java Code Examples for java.text.DecimalFormatSymbols#setMonetaryDecimalSeparator()

The following examples show how to use java.text.DecimalFormatSymbols#setMonetaryDecimalSeparator() . 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: NumberFormatter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private DecimalFormatSymbols getICUDecimalSymbols( Locale locale )
{
	DecimalFormatSymbols symbols = new DecimalFormatSymbols( locale );
	com.ibm.icu.text.DecimalFormatSymbols icuSymbols = new com.ibm.icu.text.DecimalFormatSymbols(
			locale );
	symbols.setCurrencySymbol( icuSymbols.getCurrencySymbol( ) );
	symbols.setDecimalSeparator( icuSymbols.getDecimalSeparator( ) );
	symbols.setDigit( icuSymbols.getDigit( ) );
	symbols.setGroupingSeparator( icuSymbols.getGroupingSeparator( ) );
	symbols.setInfinity( icuSymbols.getInfinity( ) );
	symbols.setInternationalCurrencySymbol( icuSymbols
			.getInternationalCurrencySymbol( ) );
	symbols.setMinusSign( icuSymbols.getMinusSign( ) );
	symbols.setMonetaryDecimalSeparator( icuSymbols
			.getMonetaryDecimalSeparator( ) );
	symbols.setNaN( icuSymbols.getNaN( ) );
	symbols.setPatternSeparator( icuSymbols.getPatternSeparator( ) );
	symbols.setPercent( icuSymbols.getPercent( ) );
	symbols.setPerMill( icuSymbols.getPerMill( ) );
	symbols.setZeroDigit( icuSymbols.getZeroDigit( ) );
	return symbols;
}
 
Example 2
Source File: NormalValuesFormatter.java    From fingen with Apache License 2.0 5 votes vote down vote up
public NormalValuesFormatter() {
    mFormat = NumberFormat.getCurrencyInstance();
    mFormat.setMinimumFractionDigits(0);
    mFormat.setMaximumFractionDigits(2);
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setCurrencySymbol("");
    dfs.setGroupingSeparator(' ');
    dfs.setMonetaryDecimalSeparator('.');
    ((DecimalFormat) mFormat).setDecimalFormatSymbols(dfs);
}
 
Example 3
Source File: CabbageFormatter.java    From fingen with Apache License 2.0 5 votes vote down vote up
public synchronized String format(BigDecimal amount){
    if (mCabbage != null) {
        mNumberFormat.setMinimumFractionDigits(mCabbage.getDecimalCount());
        mNumberFormat.setMaximumFractionDigits(mCabbage.getDecimalCount());
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setCurrencySymbol(mCabbage.getSimbol());
        dfs.setGroupingSeparator(' ');
        dfs.setMonetaryDecimalSeparator('.');
        ((DecimalFormat) mNumberFormat).setDecimalFormatSymbols(dfs);

        return mNumberFormat.format(amount.setScale(mCabbage.getDecimalCount(), mRoundingMode));
    } else {
        return "";
    }
}
 
Example 4
Source File: CurrencyCache.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
public static DecimalFormat createCurrencyFormat(Currency c) {
	DecimalFormatSymbols dfs = new DecimalFormatSymbols();
	dfs.setDecimalSeparator(charOrEmpty(c.decimalSeparator, dfs.getDecimalSeparator()));
	dfs.setGroupingSeparator(charOrEmpty(c.groupSeparator, dfs.getGroupingSeparator()));
	dfs.setMonetaryDecimalSeparator(dfs.getDecimalSeparator());
	dfs.setCurrencySymbol(c.symbol);

	DecimalFormat df = new DecimalFormat("#,##0.00", dfs);
	df.setGroupingUsed(dfs.getGroupingSeparator() > 0);
	df.setMinimumFractionDigits(c.decimals);
	df.setMaximumFractionDigits(c.decimals);
	df.setDecimalSeparatorAlwaysShown(false);
	return df;
}
 
Example 5
Source File: CurrencyEditText.java    From currency_edittext with Apache License 2.0 5 votes vote down vote up
/***
 * If user does not provide a valid locale it throws IllegalArgumentException.
 *
 * If throws an IllegalArgumentException the locale sets to default locale
 */
private void initSettings() {
    boolean success = false;
    while (!success) {
        try {
            if (fractionDigit == 0) {
                fractionDigit = Currency.getInstance(locale).getDefaultFractionDigits();
            }

            DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
            if (mGroupDivider > 0)
                symbols.setGroupingSeparator(mGroupDivider);
            groupDivider = symbols.getGroupingSeparator();

            if (mMonetaryDivider > 0)
                symbols.setMonetaryDecimalSeparator(mMonetaryDivider);
            monetaryDivider = symbols.getMonetaryDecimalSeparator();

            currencySymbol = symbols.getCurrencySymbol();

            DecimalFormat df = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
            numberFormat = new DecimalFormat(df.toPattern(), symbols);

            if (mDecimalPoints > 0) {
                numberFormat.setMinimumFractionDigits(mDecimalPoints);
            }

            success = true;
        } catch (IllegalArgumentException e) {
            Log.e(getClass().getCanonicalName(), e.getMessage());
            locale = getDefaultLocale();
        }
    }
}
 
Example 6
Source File: AmountNumberToken.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
private void fixThousandsSeparatorWithSpace(DecimalFormatSymbols symbols) {
    if(Character.isSpaceChar(formatFormat.getDecimalFormatSymbols().getGroupingSeparator())){
        symbols.setGroupingSeparator(' ');
    }
    if(Character.isWhitespace(formatFormat.getDecimalFormatSymbols().getDecimalSeparator())){
        symbols.setDecimalSeparator(' ');
    }
    if(Character.isWhitespace(formatFormat.getDecimalFormatSymbols().getMonetaryDecimalSeparator())){
        symbols.setMonetaryDecimalSeparator(' ');
    }
}
 
Example 7
Source File: Tools.java    From cncgcodecontroller with MIT License 5 votes vote down vote up
@Override
protected DecimalFormat initialValue() 
{
    DecimalFormatSymbols s = new DecimalFormatSymbols();
    s.setDecimalSeparator('.');
    s.setMonetaryDecimalSeparator('.');
    s.setMinusSign('-');
    return new DecimalFormat("0.0000",s); 
}
 
Example 8
Source File: SakaiDecimalFormatSymbolsProvider.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DecimalFormatSymbols getInstance(final Locale locale) throws IllegalArgumentException, NullPointerException {
	if (locale == null) {
		throw new NullPointerException("locale:null");
	} else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) {
		throw new IllegalArgumentException("locale:" + locale.toString());
	}

	DecimalFormatSymbols symbols = new DecimalFormatSymbols();
	symbols.setDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("DecimalSeparator", locale));
	symbols.setDigit(
			SakaiLocaleServiceProviderUtil.getChar("Digit", locale));
	symbols.setExponentSeparator(
			SakaiLocaleServiceProviderUtil.getString("ExponentSeparator", locale));
	symbols.setGroupingSeparator(
			SakaiLocaleServiceProviderUtil.getChar("GroupingSeparator", locale));
	symbols.setInfinity(
			SakaiLocaleServiceProviderUtil.getString("Infinity", locale));
	symbols.setInternationalCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("InternationalCurrencySymbol", locale));
	symbols.setCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("CurrencySymbol", locale));
	symbols.setMinusSign(
			SakaiLocaleServiceProviderUtil.getChar("MinusSign", locale));
	symbols.setMonetaryDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("MonetaryDecimalSeparator", locale));
	symbols.setNaN(
			SakaiLocaleServiceProviderUtil.getString("NaN", locale));
	symbols.setPatternSeparator(
			SakaiLocaleServiceProviderUtil.getChar("PatternSeparator", locale));
	symbols.setPercent(
			SakaiLocaleServiceProviderUtil.getChar("Percent", locale));
	symbols.setPerMill(
			SakaiLocaleServiceProviderUtil.getChar("PerMill", locale));
	symbols.setZeroDigit(
			SakaiLocaleServiceProviderUtil.getChar("ZeroDigit", locale));

	return symbols;
}
 
Example 9
Source File: SakaiDecimalFormatSymbolsProvider.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public DecimalFormatSymbols getInstance(final Locale locale) throws IllegalArgumentException, NullPointerException {
	if (locale == null) {
		throw new NullPointerException("locale:null");
	} else if (!SakaiLocaleServiceProviderUtil.isAvailableLocale(locale)) {
		throw new IllegalArgumentException("locale:" + locale.toString());
	}

	DecimalFormatSymbols symbols = new DecimalFormatSymbols();
	symbols.setDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("DecimalSeparator", locale));
	symbols.setDigit(
			SakaiLocaleServiceProviderUtil.getChar("Digit", locale));
	symbols.setExponentSeparator(
			SakaiLocaleServiceProviderUtil.getString("ExponentSeparator", locale));
	symbols.setGroupingSeparator(
			SakaiLocaleServiceProviderUtil.getChar("GroupingSeparator", locale));
	symbols.setInfinity(
			SakaiLocaleServiceProviderUtil.getString("Infinity", locale));
	symbols.setInternationalCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("InternationalCurrencySymbol", locale));
	symbols.setCurrencySymbol(
			SakaiLocaleServiceProviderUtil.getString("CurrencySymbol", locale));
	symbols.setMinusSign(
			SakaiLocaleServiceProviderUtil.getChar("MinusSign", locale));
	symbols.setMonetaryDecimalSeparator(
			SakaiLocaleServiceProviderUtil.getChar("MonetaryDecimalSeparator", locale));
	symbols.setNaN(
			SakaiLocaleServiceProviderUtil.getString("NaN", locale));
	symbols.setPatternSeparator(
			SakaiLocaleServiceProviderUtil.getChar("PatternSeparator", locale));
	symbols.setPercent(
			SakaiLocaleServiceProviderUtil.getChar("Percent", locale));
	symbols.setPerMill(
			SakaiLocaleServiceProviderUtil.getChar("PerMill", locale));
	symbols.setZeroDigit(
			SakaiLocaleServiceProviderUtil.getChar("ZeroDigit", locale));

	return symbols;
}