Java Number Format Pattern getExponentialFormat(int precision)

Here you can find the source of getExponentialFormat(int precision)

Description

Return exponential number format.

License

Open Source License

Parameter

Parameter Description
precision a parameter

Declaration

private static NumberFormat getExponentialFormat(int precision) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;
import java.text.NumberFormat;

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static Map<Integer, NumberFormat> expFormatCacheMap = new HashMap<Integer, NumberFormat>();

    /** Return exponential number format.
     */*from  w  w w .  j av  a2  s.com*/
     *  The formats are created if it has not previously been used.
     *  Constructed formats are cached.
     *
     * @param precision
     * @return
     */
    private static NumberFormat getExponentialFormat(int precision) {
        int absPrecision = Math.abs(precision);
        NumberFormat numberFormat = expFormatCacheMap.get(absPrecision);
        if (numberFormat == null) {
            final StringBuffer pattern = new StringBuffer(10);
            pattern.append("0"); //$NON-NLS-1$
            if (precision > 0) {
                pattern.append(".");
            }
            for (int i = 0; i < precision; ++i) {
                pattern.append('0');
            }
            pattern.append("E0"); //$NON-NLS-1$
            numberFormat = new DecimalFormat(pattern.toString());
            expFormatCacheMap.put(absPrecision, numberFormat);
        }
        return numberFormat;
    }
}

Related

  1. formatValue(Object value)
  2. formatWith6Digits(String input)
  3. getBigDecimalFromString(String numericValue, String numberFormat)
  4. getDataFormat(final boolean grouped, final boolean isFloat, int declen)
  5. getDefaultDecimalFormat()
  6. getF(String tStr, String formate)
  7. getFloatFormat()
  8. getFormat()
  9. getFormat(int decimals)