List of usage examples for java.text DecimalFormat applyLocalizedPattern
public void applyLocalizedPattern(String pattern)
From source file:Main.java
public static void main(String[] argv) throws Exception { DecimalFormat format = new DecimalFormat(); format.applyLocalizedPattern("##,##"); System.out.println(format.format(-123456789.12345678)); }
From source file:com.ultrapower.eoms.common.plugin.ecside.util.ExtremeUtils.java
public static String formatNumber(String format, Object value, Locale locale) { String result = null;/* ww w. ja va 2 s.co m*/ if (value == null) { return result; } if (StringUtils.isBlank(format)) { // logger.warn("The format was not defined for number [" + value.toString() + "]."); return value.toString(); } NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyLocalizedPattern(format); return df.format(Double.parseDouble(value.toString())); }
From source file:com.googlecode.jtiger.modules.ecside.util.ExtremeUtils.java
public static String formatNumber(String format, Object value, Locale locale) { String result = null;//w w w . j av a2s . c o m if (value == null) { return result; } if (StringUtils.isBlank(format)) { // logger.warn("The format was not defined for number [" + value.toString() + "]."); return value.toString(); } NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyLocalizedPattern(format); return df.format(Double.parseDouble(value.toString())); }
From source file:org.extremecomponents.util.ExtremeUtils.java
/** * //from w ww. j a va 2s .c o m * @param format * @param value * @return */ public static String formatNumber(String format, Object value, Locale locale) { String result = null; if (value == null) { return result; } if (StringUtils.isBlank(format)) { logger.error("The format was not defined for number [" + value.toString() + "]."); return value.toString(); } NumberFormat nf = NumberFormat.getNumberInstance(locale); DecimalFormat df = (DecimalFormat) nf; df.applyLocalizedPattern(format); return df.format(Double.parseDouble(value.toString())); }
From source file:org.enerj.apache.commons.beanutils.locale.converters.DecimalLocaleConverter.java
/** * Convert the specified locale-sensitive input object into an output object of the * specified type./* w w w . ja v a 2s . c o m*/ * * @param value The input object to be converted * @param pattern The pattern is used for the convertion * * @exception ConversionException if conversion cannot be performed * successfully */ protected Object parse(Object value, String pattern) throws ParseException { // DecimalFormat is not thread safe so best to construct one each time DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(locale); // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully if (pattern != null) { if (locPattern) { formatter.applyLocalizedPattern(pattern); } else { formatter.applyPattern(pattern); } } else { log.warn("No pattern provided, using default."); } return formatter.parse((String) value); }
From source file:javadz.beanutils.locale.converters.DecimalLocaleConverter.java
/** * Convert the specified locale-sensitive input object into an output * object of the specified type.// w w w . j av a 2s. c o m * * @param value The input object to be converted * @param pattern The pattern is used for the convertion * @return The converted value * * @exception org.apache.commons.beanutils.ConversionException if conversion * cannot be performed successfully * @throws ParseException if an error occurs parsing a String to a Number */ protected Object parse(Object value, String pattern) throws ParseException { if (value instanceof Number) { return value; } // Note that despite the ambiguous "getInstance" name, and despite the // fact that objects returned from this method have the same toString // representation, each call to getInstance actually returns a new // object. DecimalFormat formatter = (DecimalFormat) DecimalFormat.getInstance(locale); // if some constructors default pattern to null, it makes only sense // to handle null pattern gracefully if (pattern != null) { if (locPattern) { formatter.applyLocalizedPattern(pattern); } else { formatter.applyPattern(pattern); } } else { log.debug("No pattern provided, using default."); } return formatter.parse((String) value); }
From source file:org.enerj.apache.commons.beanutils.locale.converters.StringLocaleConverter.java
/** * Make an instance of DecimalFormat./*from w w w .j a va2s .co m*/ * * @param locale The locale * @param pattern The pattern is used for the convertion * * @exception ConversionException if conversion cannot be performed * successfully */ private DecimalFormat getDecimalFormat(Locale locale, String pattern) { DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale); // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully if (pattern != null) { if (locPattern) { numberFormat.applyLocalizedPattern(pattern); } else { numberFormat.applyPattern(pattern); } } else { log.warn("No pattern provided, using default."); } return numberFormat; }
From source file:javadz.beanutils.locale.converters.StringLocaleConverter.java
/** * Make an instance of DecimalFormat.//from w w w . ja va 2 s . c o m * * @param locale The locale * @param pattern The pattern is used for the convertion * @return The format for the locale and pattern * * @exception ConversionException if conversion cannot be performed * successfully * @throws ParseException if an error occurs parsing a String to a Number */ private DecimalFormat getDecimalFormat(Locale locale, String pattern) { DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale); // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully if (pattern != null) { if (locPattern) { numberFormat.applyLocalizedPattern(pattern); } else { numberFormat.applyPattern(pattern); } } else { log.debug("No pattern provided, using default."); } return numberFormat; }
From source file:org.totschnig.myexpenses.util.Utils.java
private static void initNumberFormat() { String prefFormat = PrefKey.CUSTOM_DECIMAL_FORMAT.getString(""); if (!prefFormat.equals("")) { DecimalFormat nf = new DecimalFormat(); try {// www . j a v a 2s .c o m nf.applyLocalizedPattern(prefFormat); numberFormat = nf; } catch (IllegalArgumentException e) { //fallback to default currency instance numberFormat = NumberFormat.getCurrencyInstance(); } } else { numberFormat = NumberFormat.getCurrencyInstance(); } }
From source file:org.mifos.platform.accounting.service.AccountingDataCacheManager.java
private String parseNumber(String number) { // FIXME should use this from common util StringBuilder pattern = new StringBuilder(); DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.ENGLISH); for (Short i = 0; i < DIGITS_BEFORE_DECIMAL; i++) { pattern.append('#'); }//w w w. j a v a2 s . c o m pattern.append(decimalFormat.getDecimalFormatSymbols().getDecimalSeparator()); for (short i = 0; i < getDigitsAfterDecimal(); i++) { pattern.append('#'); } decimalFormat.applyLocalizedPattern(pattern.toString()); decimalFormat.setDecimalSeparatorAlwaysShown(false); decimalFormat.setMinimumFractionDigits(getDigitsAfterDecimal()); return decimalFormat.format(Double.parseDouble(number)); }