Class Decimal


  • public class Decimal
    extends java.lang.Object
    Arbitrary precision decimal type.
    • Constructor Detail

      • Decimal

        public Decimal​(java.lang.String s)
      • Decimal

        public Decimal​(Decimal d)
      • Decimal

        public Decimal​(int n)
      • Decimal

        public Decimal​(long n)
      • Decimal

        public Decimal​(float n)
      • Decimal

        public Decimal​(double n)
      • Decimal

        public Decimal​(int sign,
                       int exp,
                       long[] data,
                       int flag)
    • Method Detail

      • exp

        public int exp()
      • isNaN

        public boolean isNaN()
      • isFinite

        public boolean isFinite()
      • isInfinity

        public boolean isInfinity()
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • compare

        public int compare​(Decimal v)
      • compare

        public int compare​(Decimal v,
                           boolean abs)
        Compare decimal u to v, returning the following: -1 if u < v 0 if u = v 1 if u > v If the abs flag is true compare the absolute values. Any NAN argument will always return -1.
      • properties

        public Decimal.Properties properties()
        Return the raw internal properties of the number. Use with caution.
      • abs

        public Decimal abs()
        Return the absolute value of the number.
      • negate

        public Decimal negate()
        Invert this number's sign.
      • isNegative

        public boolean isNegative()
        Indicates this number is negative.
      • signum

        public int signum()
        Signum.
      • isInteger

        public boolean isInteger()
        Check if this number can be represented as an integer without loss of precision. For example, '12.000' is the same number as '12'.
      • isZero

        public boolean isZero()
        Number is exactly zero. Exponent may exist, e.g. "0e-2" os "0.00"
      • mod

        public Decimal mod​(Decimal v)
        Divide by v and return the remainder.
      • trailingZeros

        public int trailingZeros()
        Number of trailing zeros.
      • stripTrailingZeros

        public Decimal stripTrailingZeros()
        Strip all trailing zeros.
      • scientific

        public Decimal.Scientific scientific​(int minIntDigits)
        Return a scientific representation of the number, Decimal coefficient and adjusted exponent.
      • precision

        public int precision()
        Number of digits in the unscaled value.
      • scale

        public int scale()
        Scale is the number of digits to the right of the decimal point.
      • integerDigits

        public int integerDigits()
        Number of integer digits, 1 or higher.
      • setScale

        public Decimal setScale​(int scale)
        Returns a new number with the given scale, shifting the coefficient as needed.
      • setScale

        public Decimal setScale​(int scale,
                                RoundingModeType mode)
        Returns a new number with the given scale, shifting the coefficient as needed.
      • alignexp

        public int alignexp()
        Adjusted exponent for alignment. Two numbers with the same aligned exponent are aligned for arithmetic operations. If the aligned exponents do not match one number must be shifted.
      • movePoint

        public Decimal movePoint​(int n)
        Move the decimal point -n (left) or +n (right) places. Does not change precision, only affects the exponent.
      • shiftleft

        public Decimal shiftleft​(int shift)
        Shifts all digits to the left, increasing the precision.
      • shiftright

        public Decimal shiftright​(int shift,
                                  RoundingModeType mode)
        Shifts all digits to the right, reducing the precision. Result is rounded using the given rounding mode.
      • increment

        public Decimal increment()
        Increment the least-significant integer digit.
      • decrement

        public Decimal decrement()
        Decrement the least-significant integer digit.
      • toString

        public java.lang.String toString()
        Format the number to a string, using fixed point.
        Overrides:
        toString in class java.lang.Object
      • format

        public <R> void format​(DecimalFormatter<R> formatter,
                               java.lang.String decimal,
                               java.lang.String group,
                               int minInt,
                               int minGroup,
                               int priGroup,
                               int secGroup,
                               boolean zeroScale,
                               java.lang.String[] digits)
        Low-level formatting of string and Part[] forms.
      • formatFlags

        protected java.lang.String formatFlags()
      • formatString

        protected java.lang.String formatString​(Decimal d,
                                                int minInt)
      • handleFlags

        protected Decimal handleFlags​(com.squarespace.cldrengine.api.Decimal.Op op,
                                      Decimal v)
        Handle setting of flags for operations per the IEEE-754-2008 specification. These rules are also referenced in the EcmaScript specification: 12.7.3.1 - Applying the mul operator: https://tc39.github.io/ecma262/#sec-applying-the-mul-operator 12.7.3.2 - Applying the div operator: https://tc39.github.io/ecma262/#sec-applying-the-div-operator 12.7.3.3 - Applying the mod operator: https://tc39.github.io/ecma262/#sec-applying-the-mod-operator 12.8.5 - Applying the additive operators to numbers: https://tc39.github.io/ecma262/#sec-applying-the-additive-operators-to-numbers
      • _shiftleft

        protected void _shiftleft​(int shift)
        Mutating in-place shift left.
      • _shiftright

        protected void _shiftright​(int shift)
        Mutating in-place shift right.
      • _shiftright

        protected void _shiftright​(int shift,
                                   RoundingModeType mode)
        Mutating in-place shift right.
      • _stripTrailingZeros

        protected void _stripTrailingZeros()
      • trim

        protected Decimal trim()
        Trim leading zeros from a result and reset sign and exponent accordingly.
      • trimLeadingZeros

        protected void trimLeadingZeros()
      • _increment

        protected void _increment()
        Increment the least-significant digit of the coefficient.
      • round

        protected boolean round​(long rnd,
                                long rest,
                                RoundingModeType mode)
        Return a rounding indicator for a given rounding mode.
      • isodd

        protected boolean isodd()
        Return true of this instance is odd.