List of utility methods to do Number Format Pattern
BigDecimal | getBigDecimalFromString(String numericValue, String numberFormat) get Big Decimal From String DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setGroupingSeparator(numberFormat.charAt(0)); symbols.setDecimalSeparator(numberFormat.charAt(1)); DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols(symbols); formatter.setGroupingSize(3); formatter.setMinimumIntegerDigits(1); formatter.setMaximumIntegerDigits(Integer.MAX_VALUE); ... |
String | getDataFormat(final boolean grouped, final boolean isFloat, int declen) get Data Format DecimalFormat nf = new DecimalFormat(); nf.setGroupingUsed(grouped); if (!isFloat) declen = 0; nf.setMaximumFractionDigits(declen); nf.setMinimumFractionDigits(declen); return nf.toPattern(); |
DecimalFormat | getDefaultDecimalFormat() Gets a default decimal format that should be used for formatting decimal values. final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(); decimalFormatSymbols.setDecimalSeparator('.'); final DecimalFormat format = new DecimalFormat("#0.000", decimalFormatSymbols); format.setGroupingUsed(false); return format; |
NumberFormat | getExponentialFormat(int precision) Return exponential number format. int absPrecision = Math.abs(precision); NumberFormat numberFormat = expFormatCacheMap.get(absPrecision); if (numberFormat == null) { final StringBuffer pattern = new StringBuffer(10); pattern.append("0"); if (precision > 0) { pattern.append("."); for (int i = 0; i < precision; ++i) { pattern.append('0'); pattern.append("E0"); numberFormat = new DecimalFormat(pattern.toString()); expFormatCacheMap.put(absPrecision, numberFormat); return numberFormat; |
String | getF(String tStr, String formate) get F try { df.applyPattern(formate); return format(tStr); } catch (Exception e) { return tStr; |
DecimalFormat | getFloatFormat() get Float Format return FLOAT_FORMAT;
|
NumberFormat | getFormat() get Format return new DecimalFormat("#0.00000##########################"); |
DecimalFormat | getFormat(int decimals) Returns the decimal formatter, which has a number of decimals. DecimalFormat df; df = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault()); DecimalFormatSymbols dsym = df.getDecimalFormatSymbols(); char decimalSeparator = dsym.getDecimalSeparator(); StringBuffer pattern = new StringBuffer("0"); pattern.append(decimalSeparator); for (int i = 0; i < decimals; i++) pattern.append("0"); ... |
NumberFormat | getFormat(int nbDecimale) get Format NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(nbDecimale);
format.setMinimumFractionDigits(nbDecimale);
format.setGroupingUsed(true);
return format;
|
DecimalFormat | getFormatedInt(int maxValue) get Formated Int String ret = ""; int zeros = (int) Math.floor(Math.log10(maxValue)) + 1; for (int i = 0; i < zeros; i++) { ret += "0"; return new DecimalFormat(ret); |