/* DecimalFormat.java -- Formats and parses numbers
Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
/*
* This class contains few bits from ICU4J (http://icu.sourceforge.net/),
* Copyright by IBM and others and distributed under the
* distributed under MIT/X.
*/
package java.text;
import gnu.java.lang.CPStringBuilder;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Currency;
import java.util.Locale;
/*
* This note is here for historical reasons and because I had not the courage
* to remove it :)
*
* @author Tom Tromey (tromey@cygnus.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @date March 4, 1999
*
* Written using "Java Class Libraries", 2nd edition, plus online
* API docs for JDK 1.2 from http://www.javasoft.com.
* Status: Believed complete and correct to 1.2.
* Note however that the docs are very unclear about how format parsing
* should work. No doubt there are problems here.
*/
/**
* This class is a concrete implementation of NumberFormat used to format
* decimal numbers. The class can format numbers given a specific locale.
* Generally, to get an instance of DecimalFormat you should call the factory
* methods in the <code>NumberFormat</code> base class.
*
* @author Mario Torre (neugens@limasoftware.net)
* @author Tom Tromey (tromey@cygnus.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
public class DecimalFormat extends NumberFormat
{
/** serialVersionUID for serializartion. */
private static final long serialVersionUID = 864413376551465018L;
/** Defines the default number of digits allowed while formatting integers. */
private static final int DEFAULT_INTEGER_DIGITS = 309;
/**
* Defines the default number of digits allowed while formatting
* fractions.
*/
private static final int DEFAULT_FRACTION_DIGITS = 340;
/**
* Locale-independent pattern symbols.
*/
// Happen to be the same as the US symbols.
private static final DecimalFormatSymbols nonLocalizedSymbols
= new DecimalFormatSymbols (Locale.US);
/**
* Defines if parse should return a BigDecimal or not.
*/
private boolean parseBigDecimal;
/**
* Defines if we have to use the monetary decimal separator or
* the decimal separator while formatting numbers.
*/
private boolean useCurrencySeparator;
/** Defines if the decimal separator is always shown or not. */
private boolean decimalSeparatorAlwaysShown;
/**
* Defines if the decimal separator has to be shown.
*
* This is different then <code>decimalSeparatorAlwaysShown</code>,
* as it defines if the format string contains a decimal separator or no.
*/
private boolean showDecimalSeparator;
/**
* This field is used to determine if the grouping
* separator is included in the format string or not.
* This is only needed to match the behaviour of the RI.
*/
private boolean groupingSeparatorInPattern;
/** Defines the size of grouping groups when grouping is used. */
private byte groupingSize;
/**
* This is an internal parameter used to keep track of the number
* of digits the form the exponent, when exponential notation is used.
* It is used with <code>exponentRound</code>
*/
private byte minExponentDigits;
/** This field is used to set the exponent in the engineering notation. */
private int exponentRound;
/** Multiplier used in percent style formats. */
private int multiplier;
/** Multiplier used in percent style formats. */
private int negativePatternMultiplier;
/** The negative prefix. */
private String negativePrefix;
/** The negative suffix. */
private String negativeSuffix;
/** The positive prefix. */
private String positivePrefix;
/** The positive suffix. */
private String positiveSuffix;
/** Decimal Format Symbols for the given locale. */
private DecimalFormatSymbols symbols;
/** Determine if we have to use exponential notation or not. */
private boolean useExponentialNotation;
/**
* Defines the maximum number of integer digits to show when we use
* the exponential notation.
*/
private int maxIntegerDigitsExponent;
/** Defines if the format string has a negative prefix or not. */
private boolean hasNegativePrefix;
/** Defines if the format string has a fractional pattern or not. */
private boolean hasFractionalPattern;
|