public interface DecimalQuantity
By design, this is NOT IMMUTABLE and NOT THREAD SAFE. It is intended to be an intermediate object holding state during a pass through the decimal formatting pipeline.
Implementations of this interface are free to use any internal storage mechanism.
TODO: Should I change this to an abstract class so that logic for min/max digits doesn't need to be copied to every implementation?
| Modifier and Type | Method and Description |
|---|---|
void |
adjustExponent(int delta)
Adjusts the value for the (suppressed) exponent stored when using
notation with exponents (ex: compact, scientific).
|
void |
adjustMagnitude(int delta)
Scales the number by a power of ten.
|
void |
applyMaxInteger(int maxInt)
Truncates digits from the upper magnitude of the number in order to satisfy the
specified maximum number of integer digits.
|
void |
copyFrom(DecimalQuantity other)
Sets this instance to be equal to another instance.
|
DecimalQuantity |
createCopy()
Like clone, but without the restrictions of the Cloneable interface clone.
|
byte |
getDigit(int magnitude)
Gets the digit at the specified magnitude.
|
int |
getExponent() |
int |
getLowerDisplayMagnitude()
Gets the smallest power of ten that needs to be displayed.
|
int |
getMagnitude() |
long |
getPositionFingerprint()
This method is for internal testing only.
|
StandardPlural |
getStandardPlural(PluralRules rules)
Computes the plural form for this number based on the specified set of rules.
|
int |
getUpperDisplayMagnitude()
Gets the largest power of ten that needs to be displayed.
|
boolean |
isInfinite() |
boolean |
isNaN() |
boolean |
isNegative() |
boolean |
isZeroish() |
int |
maxRepresentableDigits() |
void |
multiplyBy(BigDecimal multiplicand)
Multiply the internal value.
|
void |
negate()
Flips the sign from positive to negative and back.
|
void |
populateUFieldPosition(FieldPosition fp)
If the given
FieldPosition is a UFieldPosition, populates it with the fraction
length and fraction long value. |
void |
resetExponent()
Resets the DecimalQuantity to the value before adjustMagnitude and adjustExponent.
|
void |
roundToIncrement(BigDecimal roundingInterval,
MathContext mathContext)
Rounds the number to a specified interval, such as 0.05.
|
void |
roundToInfinity()
Rounds the number to an infinite number of decimal points.
|
void |
roundToMagnitude(int roundingMagnitude,
MathContext mathContext)
Rounds the number to a specified magnitude (power of ten).
|
void |
roundToNickel(int magnitude,
MathContext mathContext)
Rounds the number to the nearest multiple of 5 at the specified magnitude.
|
void |
setMinFraction(int minFrac)
Sets the minimum fraction digits that this
DecimalQuantity should generate. |
void |
setMinInteger(int minInt)
Sets the minimum integer digits that this
DecimalQuantity should generate. |
void |
setToBigDecimal(BigDecimal input) |
Modifier.Signum |
signum() |
BigDecimal |
toBigDecimal() |
double |
toDouble() |
String |
toExponentString()
Returns the string using ASCII digits and using exponential notation for non-zero
exponents, following the UTS 35 specification for plural rule samples.
|
long |
toLong(boolean truncateIfOverflow)
Returns a long approximating the decimal quantity.
|
String |
toPlainString()
Returns the string in "plain" format (no exponential notation) using ASCII digits.
|
void setMinInteger(int minInt)
DecimalQuantity should generate.
This method does not perform rounding.minInt - The minimum number of integer digits.void setMinFraction(int minFrac)
DecimalQuantity should generate.
This method does not perform rounding.minFrac - The minimum number of fraction digits.void applyMaxInteger(int maxInt)
maxInt - The maximum number of integer digits.void roundToIncrement(BigDecimal roundingInterval, MathContext mathContext)
If rounding to a power of ten, use the more efficient DecimalQuantity.roundToMagnitude(int, java.math.MathContext) instead.
roundingInterval - The increment to which to round.mathContext - The MathContext to use if rounding is necessary. Undefined behavior if null.void roundToNickel(int magnitude,
MathContext mathContext)
magnitude - The magnitude at which the digit should become either 0 or 5.mathContext - Rounding strategy.void roundToMagnitude(int roundingMagnitude,
MathContext mathContext)
roundingMagnitude - The power of ten to which to round. For example, a value of -2 will round to 2 decimal
places.mathContext - The MathContext to use if rounding is necessary. Undefined behavior if null.void roundToInfinity()
DecimalQuantity_AbstractBCD to adopt its exact representation.void multiplyBy(BigDecimal multiplicand)
multiplicand - The value by which to multiply.void negate()
void adjustMagnitude(int delta)
delta - The number of magnitudes of ten to change by.int getMagnitude()
throws ArithmeticException
ArithmeticException - If the value represented is zero.int getExponent()
void adjustExponent(int delta)
Adjusting the exponent is decoupled from DecimalQuantity.adjustMagnitude(int) in
order to allow flexibility for StandardPlural to be selected in
formatting (ex: for compact notation) either with or without the exponent
applied in the value of the number.
delta - The value to adjust the exponent by.void resetExponent()
boolean isZeroish()
DecimalQuantity is
zero, infinity, or NaN.boolean isNegative()
DecimalQuantity is less than zero.Modifier.Signum signum()
boolean isInfinite()
DecimalQuantity is infinite.boolean isNaN()
DecimalQuantity is not a number.double toDouble()
DecimalQuantity approximated as a double.BigDecimal toBigDecimal()
long toLong(boolean truncateIfOverflow)
getExponent (for cases such as compact notation) to return the proper long
value represented by the result.truncateIfOverflow - if false and the number does NOT fit, fails with an error.
See comment about call site guards in DecimalQuantity_AbstractBCD.javavoid setToBigDecimal(BigDecimal input)
int maxRepresentableDigits()
StandardPlural getStandardPlural(PluralRules rules)
rules - A PluralRules object representing the set of rules.StandardPlural according to the PluralRules. If the plural form is not in the
set of standard plurals, StandardPlural.OTHER is returned instead.byte getDigit(int magnitude)
magnitude - The magnitude of the digit.int getUpperDisplayMagnitude()
int getLowerDisplayMagnitude()
String toPlainString()
String toExponentString()
DecimalQuantity createCopy()
void copyFrom(DecimalQuantity other)
other - The instance to copy from.long getPositionFingerprint()
void populateUFieldPosition(FieldPosition fp)
FieldPosition is a UFieldPosition, populates it with the fraction
length and fraction long value. If the argument is not a UFieldPosition, nothing happens.fp - The UFieldPosition to populate.