List of utility methods to do Number Format Pattern
void | normalizeNumberFormat(NumberFormat numberFormat, int scale, int precision) According to the 1.7.7 spec If a logical type is invalid, for example a decimal with scale greater than its precision,then implementations should ignore the logical type and use the underlying Avro type. if (scale < precision) {
numberFormat.setMaximumIntegerDigits(precision);
numberFormat.setMaximumFractionDigits(scale);
numberFormat.setMinimumFractionDigits(scale);
|
String | objectToString(Object obj, DecimalFormat fmt) object To String fmt.setDecimalSeparatorAlwaysShown(false); if (obj instanceof Double) return fmt.format(((Double) obj).doubleValue()); if (obj instanceof Long) return fmt.format(((Long) obj).longValue()); else return obj.toString(); |
void | print(float[] array, NumberFormat nf) Prints the contents of the float array on standard out. System.out.print("["); for (int i = 0; i < array.length; i++) { System.out.print(" " + nf.format(array[i])); System.out.println(" ]"); |
void | resetDecimalFormat() reset Decimal Format decimalFormat = new DecimalFormat("#.#####"); |
void | resetDecimalFormatByLocale(Locale locale) reset Decimal Format By Locale df = (DecimalFormat) NumberFormat.getInstance(locale); |
Number | roundNumber(Number number, DecimalFormat format) round Number Number formattedNumber = null; try { formattedNumber = format.parse(format.format(number)); } catch (ParseException ex) { return formattedNumber; |
String | stringFormat(BigDecimal value) string Format DecimalFormat df = new DecimalFormat("#0.00"); return df.format(value); |
String | stringToReais(String unformatted, boolean comSimbolo) string To Reais DecimalFormatSymbols symbols = new DecimalFormatSymbols(new Locale("pt", "BR")); symbols.setGroupingSeparator('.'); symbols.setDecimalSeparator(','); if (!comSimbolo) { symbols.setCurrencySymbol(""); DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("pt", "BR")); decimalFormat.setDecimalFormatSymbols(symbols); ... |
String | strToFormatedNumber(String str) strToFormatedNumber long value = Long.parseLong(str); NumberFormat FORMAT = NumberFormat.getInstance(); FORMAT.setGroupingUsed(true); return FORMAT.format(value); |
String | toAccountantFormat(String str, int scale) to Accountant Format if (str != null) { String temp = "#,###,###,###,##0."; for (int i = 0; i < scale; i++) { temp += "0"; return new java.text.DecimalFormat(temp).format(Double.valueOf(str)); } else { return "0.00"; ... |