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

doublegetCorrectionValue(double basicValue, int digit)
get Correction Value
if (digit < 0)
    return basicValue;
StringBuilder sb = new StringBuilder("#");
if (digit > 0) {
    sb.append("0.");
    for (int i = 0; i < digit; i++) {
        sb.append("0");
DecimalFormat format = new DecimalFormat(sb.toString());
return Double.parseDouble(format.format(basicValue));
DecimalFormatgetDecimalFormat()
get Decimal Format
NumberFormat nf = NumberFormat.getNumberInstance(loc);
return (DecimalFormat) nf;
DecimalFormatgetDecimalFormat()
get Decimal Format
return mDecFmt;
DecimalFormatgetDecimalFormat()
get Decimal Format
return s_decimalFormat.get();
DecimalFormatgetDecimalFormat()
get Decimal Format
if (decimalFormat == null) {
    decimalFormat = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);
    decimalFormat.setParseBigDecimal(true);
return decimalFormat;
DecimalFormatgetDecimalFormat(final int decimalPlaces)
Gets a decimal format that with the desired number of decimal places.
if (decimalPlaces < 0) {
    throw new IllegalArgumentException("decimalPlaces must be non-negative");
final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
decimalFormatSymbols.setDecimalSeparator('.');
final StringBuilder builder = new StringBuilder();
builder.append("#0");
if (decimalPlaces > 0) {
...
DecimalFormatgetDecimalFormat(int decimalPlaces, Locale locale)
get Decimal Format
StringBuffer sb = new StringBuffer();
sb.append("#,###,##0.");
for (int i = 0; i < decimalPlaces; i++) {
    sb.append('0');
DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(locale);
df.applyPattern(sb.toString());
return df;
...
DecimalFormatgetDecimalFormat(int precision)
Get Decimal Format for a specific precision
if (precision <= 0) {
    return integerFormat;
char[] chars = new char[precision];
Arrays.fill(chars, '0');
String format = MessageFormat.format(formatTemplate, new String(chars));
return new DecimalFormat(format);
NumberFormatgetDecimalFormat(int precision)
Return decimal number format.
int absPrecision = Math.abs(precision);
NumberFormat numberFormat = decimalFormatCacheMap.get(absPrecision);
if (numberFormat == null) {
    numberFormat = new DecimalFormat("0"); 
    numberFormat.setMinimumFractionDigits(absPrecision);
    numberFormat.setMaximumFractionDigits(absPrecision);
    decimalFormatCacheMap.put(absPrecision, numberFormat);
return numberFormat;
DecimalFormatgetDecimalFormat(int precision, String force)
Gets decimal format.
String s = force + ".";
for (int i = 0; i < precision; i++)
    s += force;
return new DecimalFormat(s);