View Javadoc

1   /*
2    *  File: FormatHelper.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.misc;
12  
13  import java.text.NumberFormat;
14  
15  /**
16   * @author Peter Kliem
17   * @version $Id: FormatHelper.java 242 2007-02-11 21:05:07Z olk $
18   */
19  public class FormatHelper {
20      private static NumberFormat __double2Digits;
21  
22      public static NumberFormat NFDouble2Digits() {
23          if (__double2Digits == null) {
24              __double2Digits = NumberFormat.getNumberInstance();
25              __double2Digits.setMaximumFractionDigits(2);
26              __double2Digits.setMinimumFractionDigits(2);
27          }
28          return __double2Digits;
29      }
30  
31      private static NumberFormat __int2Digits;
32  
33      public static NumberFormat NFInt2Digits() {
34          if (__int2Digits == null) {
35              __int2Digits = NumberFormat.getNumberInstance();
36              __int2Digits.setMaximumIntegerDigits(2);
37              __int2Digits.setMinimumIntegerDigits(2);
38          }
39          return __int2Digits;
40      }
41  
42  }