Java Utililty Methods Decimal Format

List of utility methods to do Decimal Format

Description

The list of methods to do Decimal Format are organized into topic(s).

Method

StringdecimalFormat(double number)
decimal Format
return decimalFormat.format(number);
StringdecimalFormat(Double numeric)
Format Decimal number
Locale.setDefault(new Locale("pt", "BR"));
DecimalFormat decimal = new DecimalFormat();
decimal.applyPattern("#,##0.00");
return decimal.format(numeric / NUMBER_100).replaceAll(",", ".");
StringdecimalFormat(double value, int decimalCnt)
 
String resultValue = "";
String pattern = "";
if (decimalCnt > 0) {
    for (int i = 0; i < decimalCnt; i++) {
        pattern += "#";
    pattern = "." + pattern;
    DecimalFormat df = new DecimalFormat(pattern);
...
StringdecimalFormat(Object obj)
decimal Format
if (null == obj)
    return "";
DecimalFormat df = new DecimalFormat("0.00");
return df.format(obj);
DecimalFormatdecimalFormat(String pattern)
Creates a format.
return new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(Locale.ROOT));
StringdecimalFormat(String pattern, double value)
decimal Format
return new DecimalFormat(pattern).format(value);
StringdecimalFormatLabel(final long value, final long divider, final String unit)
Formats a decimal value using a specified divider
final double result = divider > 1 ? (double) value / (double) divider : (double) value;
return new DecimalFormat("#,##0.#").format(result) + " " + unit;
StringdecimalPointTwo(Float input)
decimal Point Two
if (input == null || input == 0) {
    return "0.0";
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.FLOOR);
return df.format(input);
StringdecimalString(double d, boolean forceDigits)
decimal String
return forceDigits ? dfForce.format(d) : df.format(d);
StringencodeDouble(double d)
encode Double
String decimalString = FULL_DECIMAL_FORMAT.format(d);
int splitPoint = decimalString.indexOf('E');
String significand = decimalString.substring(0, splitPoint);
String exponent = decimalString.substring(splitPoint + 1);
boolean negativeExponent = exponent.startsWith("-");
String result;
if (significand.startsWith("-")) {
    BigDecimal significandValue = new BigDecimal(significand);
...