Here you can find the source of getDecimalFormat(int precision)
Parameter | Description |
---|---|
precision | a parameter |
private static NumberFormat getDecimalFormat(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> decimalFormatCacheMap = new HashMap<Integer, NumberFormat>(); /** Return decimal number format. *//from w ww . java 2 s.c o m * The formats are created if it has not previously been used. * Constructed formats are cached. * * @param precision * @return */ private static NumberFormat getDecimalFormat(int precision) { int absPrecision = Math.abs(precision); NumberFormat numberFormat = decimalFormatCacheMap.get(absPrecision); if (numberFormat == null) { numberFormat = new DecimalFormat("0"); //$NON-NLS-1$ numberFormat.setMinimumFractionDigits(absPrecision); numberFormat.setMaximumFractionDigits(absPrecision); decimalFormatCacheMap.put(absPrecision, numberFormat); } return numberFormat; } }