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

The following examples show how to use java.text.DecimalFormatSymbols#getMonetaryDecimalSeparator() . 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: MonetaryFormat.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configure this instance with values from a {@link Locale}.
 */
public MonetaryFormat withLocale(Locale locale) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    char negativeSign = dfs.getMinusSign();
    char zeroDigit = dfs.getZeroDigit();
    char decimalMark = dfs.getMonetaryDecimalSeparator();
    return new MonetaryFormat(negativeSign, positiveSign, zeroDigit, decimalMark, minDecimals, decimalGroups,
            shift, roundingMode, codes, codeSeparator, codePrefixed);
}
 
Example 2
Source File: MonetaryFormat.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configure this instance with values from a {@link Locale}.
 */
public MonetaryFormat withLocale(Locale locale) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    char negativeSign = dfs.getMinusSign();
    char zeroDigit = dfs.getZeroDigit();
    char decimalMark = dfs.getMonetaryDecimalSeparator();
    return new MonetaryFormat(negativeSign, positiveSign, zeroDigit, decimalMark, minDecimals, decimalGroups,
            shift, roundingMode, codes, codeSeparator, codePrefixed);
}
 
Example 3
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 4
Source File: MonetaryFormat.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configure this instance with values from a {@link Locale}.
 */
public MonetaryFormat withLocale(Locale locale) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
    char negativeSign = dfs.getMinusSign();
    char zeroDigit = dfs.getZeroDigit();
    char decimalMark = dfs.getMonetaryDecimalSeparator();
    return new MonetaryFormat(negativeSign, positiveSign, zeroDigit, decimalMark, minDecimals, decimalGroups,
            shift, roundingMode, codes, codeSeparator, codePrefixed);
}
 
Example 5
Source File: DefaultMonetaryAmountFormat.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
private String getNumberPattern(String token, DecimalFormat format) {
    // Parse the token for
    int first = -1;
    int last = -1;
    DecimalFormatSymbols syms = format.getDecimalFormatSymbols();
    char[] chars = token.toCharArray();
    int nonMatching = 0;
    for(int i=0; i<chars.length;i++){
        if(chars[i] ==syms.getMonetaryDecimalSeparator() ||
                chars[i] ==syms.getMonetaryDecimalSeparator() ||
                chars[i] ==syms.getDecimalSeparator() ||
                chars[i] ==syms.getGroupingSeparator() ||
                chars[i] ==syms.getMinusSign() ||
                chars[i] ==syms.getPercent() ||
                chars[i] ==syms.getPerMill() ||
                chars[i] ==syms.getZeroDigit() ||
                chars[i] ==syms.getDigit()){
            if(first<0)first = i;
            last = i;
            nonMatching = 0;
        }else{
            nonMatching++;
        }
        if(last!=-1 && first<last && nonMatching>2){
            break;
        }
    }
    if(last!=-1 && first<last){
        return token.substring(first, last+1);
    }
    return null;
}