Java Decimal Format decimalFormat()

Here you can find the source of decimalFormat()

Description

decimal Format

License

Apache License

Declaration

public static DecimalFormat decimalFormat() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;

public class Main {
    public static DecimalFormat decimalFormat() {
        return decimalFormat(false);
    }/*from w  w  w.  ja v  a 2 s  . c  om*/

    public static DecimalFormat decimalFormat(boolean showSign) {
        return decimalFormat(true, showSign);
    }

    public static DecimalFormat decimalFormat(boolean useGroupingSeparator, boolean showSign) {
        DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US);
        DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();

        if (useGroupingSeparator) {
            symbols.setGroupingSeparator(' ');
        } else {
            formatter.setGroupingUsed(false);
        }

        formatter.setDecimalFormatSymbols(symbols);

        if (showSign) {
            formatter.setPositivePrefix("+");
        }

        return formatter;
    }
}

Related

  1. adjustDoubleNumber(Double doubleNumber, int maxIntPart, int maxFloatPart)
  2. createMeanRmsString(double values[])
  3. decimal2percent(double decimal, int pos)
  4. decimal2string(BigDecimal arg, Locale loc)
  5. decimalConversation(double amount)
  6. decimalFormat(double d)
  7. decimalFormat(double no)
  8. decimalFormat(double number)
  9. decimalFormat(Double numeric)