A DigitList is really a representation of a floating point value. It may be an integer value; we assume that a double has sufficient precision to represent all digits of a long.
The DigitList representation consists of a string of characters, which are the digits radix 10, from '0' to '9'. It also has a radix 10 exponent associated with it. The value represented by a DigitList object can be computed by mulitplying the fraction f, where 0 <= f < 1, derived by placing all the digits of the list to the right of the decimal point, by 10^exponent.
Locale, Format, NumberFormat, DecimalFormat, ChoiceFormat, MessageFormat
| Modifier and Type | Field and Description |
|---|---|
| private static final boolean | |
| public int | |
| public int | decimalAt
These data members are intentionally public and can be set directly. |
| public byte[] | |
| private boolean | |
| private static final byte[] | |
| public static final int | MAX_COUNT
The maximum number of significant digits in an IEEE 754 double, that is, in a Java double. |
| private RoundingMode |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public Object | Returns: a clone of this instance.Overrides java. Creates a copy of this object. |
| public boolean | |
| private void | |
| pack-priv boolean | Returns: true if this number fits into a Java longtrue if this number should be regarded as positive isPositive, boolean true if -0 should be regarded as identical to
+0; otherwise they are considered distinct ignoreNegativeZero)Return true if the number represented by this object can fit into a long. |
| public BigDecimal | |
| public double | getDouble()
Utility routine to get the value of the digit list If (count == 0) this returns 0.0, unlike Double.parseDouble("") which throws NumberFormatException. |
| public long | |
| public int | |
| pack-priv boolean | |
| private boolean | nonZeroAfterIndex(int index)
Return true if there exists a non-zero digit in the digit list from the given index until the end. |
| private void | round(int
The maximum number of digits to be shown. maximumDigits, boolean whether or not rounding up has already happened. alreadyRounded, boolean whether or not collected digits provide
an exact decimal representation of the value.
Upon return, count will be less than or equal to maximumDigits. valueExactAsDecimal)Round the representation to the given number of digits. |
| private void | roundInt(int
The maximum number of digits to be shown.
Upon return, count will be less than or equal to maximumDigits. maximumDigits)Round the representation to the given number of digits. |
| private int | Returns: The new maximum digits after rounding.The maximum number of digits to be shown. maximumDigits)Round the digit list up numerically. |
| pack-priv void | set(boolean
Boolean value indicating whether the number is negative. isNegative, double Value to be converted; must not be Inf, -Inf, Nan,
or a value <= 0. source, int The most fractional digits which should
be converted. maximumFractionDigits)Set the digit list to a representation of the given double value. |
| pack-priv void | set(boolean
Boolean value indicating whether the number is negative. isNegative, double Value to be converted; must not be Inf, -Inf, Nan,
or a value <= 0. source, int The most fractional or total digits which should
be converted. maximumDigits, boolean If true, then maximumDigits is the maximum
fractional digits to be converted. If false, total digits. fixedPoint)Set the digit list to a representation of the given double value. |
| private void | set(boolean isNegative, int exp, boolean
whether or not rounding up has already happened. roundedUp, boolean whether or not collected digits provide
an exact decimal representation of the value. valueExactAsDecimal, int maximumDigits, boolean fixedPoint)Generate a representation of the form DDDDD, DDDDD.DDDDD, or DDDDDE+/-DDDDD. |
| pack-priv void | |
| pack-priv void | set(boolean
Boolean value indicating whether the number is negative. isNegative, long Value to be converted; must be >= 0 or ==
Long.MIN_VALUE. source, int The most digits which should be converted.
If maximumDigits is lower than the number of significant digits
in source, the representation will be rounded. Ignored if <= 0. maximumDigits)Set the digit list to a representation of the given long value. |
| pack-priv void | set(boolean
Boolean value indicating whether the number is negative. isNegative, BigDecimal Value to be converted; must not be a value <= 0. source, int The most fractional or total digits which should
be converted. maximumDigits, boolean If true, then maximumDigits is the maximum
fractional digits to be converted. If false, total digits. fixedPoint)Set the digit list to a representation of the given BigDecimal value. |
| pack-priv void | set(boolean
Boolean value indicating whether the number is negative. isNegative, BigInteger Value to be converted; must be >= 0. source, int The most digits which should be converted.
If maximumDigits is lower than the number of significant digits
in source, the representation will be rounded. Ignored if <= 0. maximumDigits)Set the digit list to a representation of the given BigInteger value. |
| pack-priv void | |
| private boolean | Returns: true if digitmaximumDigits-1 should be
incrementedthe number of digits to keep, from 0 to
maximumDigits, boolean count-1. If 0, then all digits are rounded away, and
this method returns true if a one should be generated (e.g., formatting
0.09 with "#.#").whether or not rounding up has already happened. alreadyRounded, boolean whether or not collected digits provide
an exact decimal representation of the value. valueExactAsDecimal)Return true if truncating the representation to the given number of digits will result in an increment to the last digit. |
| public String |
| COMPAT | back to summary |
|---|---|
| private static final boolean COMPAT | |
| count | back to summary |
|---|---|
| public int count | |
| decimalAt | back to summary |
|---|---|
| public int decimalAt These data members are intentionally public and can be set directly. The value represented is given by placing the decimal point before digits[decimalAt]. If decimalAt is < 0, then leading zeros between the decimal point and the first nonzero digit are implied. If decimalAt is > count, then trailing zeros between the digits[count-1] and the decimal point are implied. Equivalently, the represented value is given by f * 10^decimalAt. Here f is a value 0.1 <= f < 1 arrived at by placing the digits in Digits to the right of the decimal. DigitList is normalized, so if it is non-zero, digits[0] is non-zero. We don't allow denormalized numbers because our exponent is effectively of unlimited magnitude. The count value contains the number of significant digits present in digits[]. Zero is represented by any DigitList with count == 0 or with each digits[i] for all i <= count == '0'. | |
| digits | back to summary |
|---|---|
| public byte[] digits | |
| isNegative | back to summary |
|---|---|
| private boolean isNegative | |
| LONG_MIN_REP | back to summary |
|---|---|
| private static final byte[] LONG_MIN_REP
| |
| MAX_COUNT | back to summary |
|---|---|
| public static final int MAX_COUNT The maximum number of significant digits in an IEEE 754 double, that is, in a Java double. This must not be increased, or garbage digits will be generated, and should not be decreased, or accuracy will be lost. | |
| roundingMode | back to summary |
|---|---|
| private RoundingMode roundingMode | |
| DigitList | back to summary |
|---|---|
| pack-priv DigitList() | |
| append | back to summary |
|---|---|
| public void append(char digit) Appends a digit to the list, extending the list when necessary. | |
| clear | back to summary |
|---|---|
| public void clear() Clears out the digits. Use before appending them. Typically, you set a series of digits with append, then at the point you hit the decimal point, you set myDigitList.decimalAt = myDigitList.count; then go on appending digits. | |
| clone | back to summary |
|---|---|
| public Object clone() Overrides java. Creates a copy of this object.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. equality test between two digit lists. | |
| extendDigits | back to summary |
|---|---|
| private void extendDigits(int len) | |
| fitsIntoLong | back to summary |
|---|---|
| pack-priv boolean fitsIntoLong(boolean isPositive, boolean ignoreNegativeZero) Return true if the number represented by this object can fit into a long.
| |
| getBigDecimal | back to summary |
|---|---|
| public BigDecimal getBigDecimal() Utility routine to get the value of the digit list. If (count == 0) this does not throw a NumberFormatException, unlike BigDecimal(""). | |
| getDouble | back to summary |
|---|---|
| public double getDouble() Utility routine to get the value of the digit list If (count == 0) this returns 0.0, unlike Double.parseDouble("") which throws NumberFormatException. | |
| getLong | back to summary |
|---|---|
| public long getLong() Utility routine to get the value of the digit list. If (count == 0) this returns 0, unlike Long.parseLong("") which throws NumberFormatException. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Generates the hash code for the digit list. | |
| isZero | back to summary |
|---|---|
| pack-priv boolean isZero() Return true if the represented number is zero. | |
| nonZeroAfterIndex | back to summary |
|---|---|
| private boolean nonZeroAfterIndex(int index) Return true if there exists a non-zero digit in the digit list from the given index until the end. | |
| round | back to summary |
|---|---|
| private void round(int maximumDigits, boolean alreadyRounded, boolean valueExactAsDecimal) Round the representation to the given number of digits.
| |
| roundInt | back to summary |
|---|---|
| private void roundInt(int maximumDigits) Round the representation to the given number of digits.
| |
| roundUp | back to summary |
|---|---|
| private int roundUp(int maximumDigits) Round the digit list up numerically. This involves incrementing digits from the LSD to the MSD.
| |
| set | back to summary |
|---|---|
| pack-priv void set(boolean isNegative, double source, int maximumFractionDigits) Set the digit list to a representation of the given double value. This method supports fixed-point notation.
| |
| set | back to summary |
|---|---|
| pack-priv void set(boolean isNegative, double source, int maximumDigits, boolean fixedPoint) Set the digit list to a representation of the given double value. This method supports both fixed-point and exponential notation.
| |
| set | back to summary |
|---|---|
| private void set(boolean isNegative, int exp, boolean roundedUp, boolean valueExactAsDecimal, int maximumDigits, boolean fixedPoint) Generate a representation of the form DDDDD, DDDDD.DDDDD, or DDDDDE+/-DDDDD.
| |
| set | back to summary |
|---|---|
| pack-priv void set(boolean isNegative, long source) Utility routine to set the value of the digit list from a long | |
| set | back to summary |
|---|---|
| pack-priv void set(boolean isNegative, long source, int maximumDigits) Set the digit list to a representation of the given long value.
| |
| set | back to summary |
|---|---|
| pack-priv void set(boolean isNegative, BigDecimal source, int maximumDigits, boolean fixedPoint) Set the digit list to a representation of the given BigDecimal value. This method supports both fixed-point and exponential notation.
| |
| set | back to summary |
|---|---|
| pack-priv void set(boolean isNegative, BigInteger source, int maximumDigits) Set the digit list to a representation of the given BigInteger value.
| |
| setRoundingMode | back to summary |
|---|---|
| pack-priv void setRoundingMode(RoundingMode r) Set the rounding mode | |
| shouldRoundUp | back to summary |
|---|---|
| private boolean shouldRoundUp(int maximumDigits, boolean alreadyRounded, boolean valueExactAsDecimal) Return true if truncating the representation to the given number of digits will result in an increment to the last digit. This method implements the rounding modes defined in the java.math.RoundingMode class. [bnf]
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |