Big Decimal
Implementation of floating-point arbitrary precision arithmetic.
Each object of this class represents an immutable large floating point number. The underlying implementation uses BigInteger to represent sign and significand, and Long to represent the exponent.
DecimalMode defines the precision and desired RoundingMode when using instances of this class in arithmetic operations, but if DecimalMode is supplied to the operation it will override instances DecimalMode
Scale, or the number of digits to the right of the decimal, can also be specified. Default is no scale, which puts no restriction on number of digits to the right of the decimal. When scale is specified, a RoundingMode other than RoundingMode.NONE is also required.
When arithmetic operations have both operands unlimited precision and no scaling, the result is also unlimited precision and no scale. When an operation mixes an unlimited precision operand and a scaled operand, the result is unlimited precision. When both operands have scale, whether unlimited precision or limited precision, then these rules for scale of the result are used:
- add, subtract - max of the two scales
- multiply - sum of the two scales
- divide - min of the two scales
Properties
precisionLimit is zero if precision unlimited. Otherwise returns DecimalMode.decimalPrecision.
Functions
Return Absolute value
Add two BigDecimal and return result in a new instance of BigDecimal. Default decimal mode will be used.
Add two BigDecimal and return result in a new instance of BigDecimal.
Return this truncated by using ceil rounding
Compare to other BigDecimal
Creates a copy of this BigDecimal with some different elements (significand/exponent/decimalMode)
Decrement by one
Divide two BigDecimal and return result in a new instance of BigDecimal
Quotient and remainder of integer division on this bigDecimal. If there is no rounding mode defined in decimal mode #RoundingMode.FLOOR will be used. Uses truncating division to determine quotient, which means that the sign of remainder will be same as sign of dividend
Narrow to a double.
Narrow to a float.
Return this truncated by using floor rounding
Incerement by one
Moves the decimal point by creating a new instance with a different exponent. Positive values move the decimal point to the right, negative values move the decimal point to the left.
Multiply two BigDecimal and return result in a new instance of BigDecimal Default decimal mode will be used
Multiply two BigDecimal and return result in a new instance of BigDecimal
Negate this BigDecimal
Returns the number of digits representing this number i.e. 12.345 will return 5 0.001 will return 4 123000 will return 6 0.010000 will return 3 (trailing zeros are not counted)
Exponentiate this BigDecimal by some exponent
Exponentiate this BigDecimal by some exponent. Note that while exponentiation with positive numbers can have infinite precision, exponentiation with negative numbers is division and as such has the same limitation as division.
Remainder of integer division operation. Remainder has same sign as dividend.
Remainder of integer division operation. Remainder has same sign as dividend
Remainder of integer division operation. Returns the least absolute remainder (remainder has same sign as dividend)
Remainder of integer division on this bigDecimal. If there is no rounding mode defined in decimal mode #RoundingMode.FLOOR will be used
Round using specific DecimalMode and return rounded instance. This is applied only to significand.
Round the BigDecimal to a specific length. If position is set to 0, a ArithmeticException is thrown. Use this for rounding when not using scale. I.e.
Round the BigDecimal to a specific length AFTER the decimal point. If position is set to 0 a integer value is returned Use this only if not using scale.
Overwrite the underlying backing structure with zeroes. Meant to be used by libraries that require it for security purposes. NOTE: This breaks the immutability of BigNumber, and this instance cannot be used for further calculations. If it used the results are undefined.
Convert the current value to Short.
Subtract two BigDecimal and return result in a new instance of BigDecimal. Default decimal mode will be used
Subtract two BigDecimal and return result in a new instance of BigDecimal
Convert to big integer by truncating
Created by Ugljesa Jovanovic ugljesa.jovanovic@ionspin.com on 24-Mar-2019
Convenience method matching Java BigDecimal, same functionality as toStringExpanded
Return this big decimal in expanded notation. i.e. 123000000 for 1.23E+9 or 0.00000000123 for 1.23E-9
Convert the current value to UByte.
Convert the current value to ULong.
Returns a new negated instance
Convert the current value to UShort.