Example usage for java.text DecimalFormatSymbols DecimalFormatSymbols

List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols

Introduction

In this page you can find the example usage for java.text DecimalFormatSymbols DecimalFormatSymbols.

Prototype

public DecimalFormatSymbols(Locale locale) 

Source Link

Document

Create a DecimalFormatSymbols object for the given locale.

Usage

From source file:org.unitime.localization.impl.Localization.java

public static NumberFormat getNumberFormat(String pattern) {
    return new DecimalFormat(pattern, new DecimalFormatSymbols(getJavaLocale()));
}

From source file:org.netxilia.api.impl.format.NumberFormatter.java

protected NumberFormat buildFormat() {
    if (localeObject == null) {
        throw new IllegalStateException("The init method was not called");
    }/*w  w w.  j  av a  2 s  .  co  m*/
    return new DecimalFormat(getPattern(), new DecimalFormatSymbols(localeObject));
}

From source file:org.techytax.helper.AmountHelper.java

public static String formatWithEuroSymbol(BigInteger amount) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat(" ###,###,###,##0", otherSymbols);
    return df.format(amount.doubleValue());
}

From source file:org.webguitoolkit.ui.controls.util.conversion.NumberAllConverter.java

/**
 * check if the input string is a legal number. It does NOT return a Numberobject.
 * Itseem that this is a bug in BeanUtilBean class (maybe we shopuld update)
 * Try: BeanUtilBean.setProperty( Pump, "hours", new Float(24))
 * with Pump.setHours(int value) taking an int as input.
 * You will see, that it will store '0', because it converts the float into string,
 * then back to int, and get an parseexception.
 * /*from   ww  w . j av  a 2s .co m*/
 * @return the input string
 * @exception ConversionException if the input if not a legal number
 */
public Object parse(String textRep) throws ConversionException {
    // no mandatory field, empty means value zero.
    if (StringUtils.isEmpty(textRep))
        return new Float(0f);
    formatter = new DecimalFormat(pattern, new DecimalFormatSymbols(TextService.getLocale()));
    ParsePosition pos = new ParsePosition(0);
    lastNumber = formatter.parse(textRep, pos);
    // to avoid null pointer -return float with 0
    if (lastNumber == null)
        throw new ConversionException(
                TextService.getString("converter.NumberConverter.message@Cannot convert into number."));
    if (pos.getIndex() < textRep.length()) {
        throw new ConversionException(
                TextService.getString("converter.NumberConverter.message@Cannot convert into number."));
    }
    // must decode into string using default locale of system
    // because it is going to be translated back!
    // why is this fucking BeanUtil converter stuff so complicated and error-prone?
    return lastNumber.toString();
}

From source file:no.abmu.questionnaire.propertyeditors.FloatAdvancedCustomNumberEditor.java

public FloatAdvancedCustomNumberEditor(Class numberClass, NumberFormat numberFormat, boolean allowEmpty,
        Locale locale) {/*from   w  ww  .j  ava 2  s  .c  om*/
    super(numberClass, numberFormat, allowEmpty);
    this.locale = locale;
    DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
    this.decimalSeparator = ',';//decimalFormatSymbols.getDecimalSeparator();
    this.groupingSeparator = '.';//decimalFormatSymbols.getGroupingSeparator();
    decimalSeparatorPattern = Pattern.compile("[" + decimalSeparator + "]");
    groupingSeparatorPattern = Pattern.compile("[" + groupingSeparator + "]");
}

From source file:org.techytax.helper.AmountHelper.java

public static String formatWithEuroSymbol(BigDecimal amount) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat(" ###,###,###,##0.00", otherSymbols);
    return df.format(amount.doubleValue());
}

From source file:org.vulpe.controller.struts.commons.beans.converter.DecimalConverter.java

public Object convert(final Class type, final Object value) {
    try {// ww  w .ja v a 2 s . c o m
        final VulpeApplication vulpeApplication = VulpeConfigHelper.getApplicationConfiguration();
        final String currencySymbol = vulpeApplication.view().showCurrencySymbol()
                ? vulpeApplication.view().currencySymbol()
                : "";
        final String locale[] = vulpeApplication.localeCode().split("_");
        final DecimalFormat valueFormat = new DecimalFormat(currencySymbol + "#,##0.00",
                new DecimalFormatSymbols(new Locale(locale[0], locale[1])));
        if (value instanceof String) {
            if (StringUtils.isNotBlank(value.toString())) {
                String newValue = StringUtils.replace(value.toString(), currencySymbol, "");
                newValue = StringUtils.replace(newValue, " ", "");
                newValue = StringUtils.replace(newValue, ".", "");
                newValue = StringUtils.replace(newValue, ",", ".");
                return new BigDecimal(newValue);
            }
        } else if (value instanceof Double && String.class.equals(type)) {
            return valueFormat.format(value);
        } else if (value instanceof Double) {
            return value;
        }
    } catch (Exception e) {
        LOG.error("Error on convert decimal value: " + value);
        throw new TypeConversionException("Error on convert decimal value: " + value, e);
    }
    return null;
}

From source file:org.vulpe.controller.struts.commons.beans.converter.BigDecimalConverter.java

public Object convert(final Class type, final Object value) {
    try {//from www .  ja v  a 2s.co m
        final VulpeApplication vulpeApplication = VulpeConfigHelper.getApplicationConfiguration();
        final String currencySymbol = vulpeApplication.view().showCurrencySymbol()
                ? vulpeApplication.view().currencySymbol()
                : "";
        final String locale[] = vulpeApplication.localeCode().split("_");
        final DecimalFormat valueFormat = new DecimalFormat(currencySymbol + "#,##0.00",
                new DecimalFormatSymbols(new Locale(locale[0], locale[1])));
        if (value instanceof String) {
            if (StringUtils.isNotBlank(value.toString())) {
                String newValue = StringUtils.replace(value.toString(), currencySymbol, "");
                newValue = StringUtils.replace(newValue, " ", "");
                newValue = StringUtils.replace(newValue, ".", "");
                newValue = StringUtils.replace(newValue, ",", ".");
                return new BigDecimal(newValue);
            }
        } else if (value instanceof BigDecimal && String.class.equals(type)) {
            return valueFormat.format(value);
        } else if (value instanceof BigDecimal) {
            return value;
        }
    } catch (Exception e) {
        LOG.error("Error on convert decimal value: " + value);
        throw new TypeConversionException("Error on convert decimal value: " + value, e);
    }
    return null;
}

From source file:org.openvpms.web.resource.i18n.format.NumberFormatter.java

/**
 * Returns a number format for the specified key.
 *
 * @param key the key/*from  ww w.j a  va  2 s . c om*/
 * @return the corresponding locale
 */
public static NumberFormat getFormat(String key) {
    Locale locale = Messages.getLocale();
    String pattern = Messages.get(key);
    try {
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
        return new DecimalFormat(pattern, symbols);
    } catch (Exception exception) {
        log.error("Failed to create format for key=" + key + ", locale=" + locale + ", pattern=" + pattern,
                exception);
        return NumberFormat.getInstance();
    }
}

From source file:com.jkoolcloud.tnt4j.streams.utils.NumericFormatter.java

/**
 * Sets the format pattern string for this formatter.
 *
 * @param pattern/*w w  w.  j ava 2  s . c om*/
 *            format pattern - can be set to {@code null} to use default representation.
 * @param locale
 *            locale for decimal format to use.
 */
public void setPattern(String pattern, String locale) {
    this.pattern = pattern;
    formatter = StringUtils.isEmpty(pattern) ? null
            : StringUtils.isEmpty(locale) ? new DecimalFormat(pattern)
                    : new DecimalFormat(pattern, new DecimalFormatSymbols(Utils.getLocale(locale)));
}