Here you can find the source of getExponentialFormat(int precision)
Parameter | Description |
---|---|
precision | a parameter |
private static NumberFormat getExponentialFormat(int precision)
//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; } }