BigDecimal

Inheritors

JavaBigDecimalAdapter

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose _scale is this._scale().

Link copied to clipboard
abstract val precision: Int

Returns the _precision of this BigDecimal. (The _precision is the number of digits in the unscaled value.)

Link copied to clipboard
abstract val scale: Int

Returns the _scale of this BigDecimal. If zero or positive, the _scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the _scale. For example, a _scale of -3 means the unscaled value is multiplied by 1000.

Link copied to clipboard
abstract val signum: Int

Returns the _signum function of this BigDecimal.

Link copied to clipboard

Returns a BigInteger whose value is the unscaled value of this BigDecimal. (Computes (this * 10<sup>this._scale()</sup>).)

Functions

Link copied to clipboard

Returns a BigDecimal whose value is the absolute value of this BigDecimal, with rounding according to the context settings.

Link copied to clipboard
abstract operator override fun compareTo(other: BigDecimal): Int

Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in value but have a different _scale (like 2.0 and 2.00) are considered equal by this method. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y)<op>0), where <op> is one of the six comparison operators.

Link copied to clipboard
abstract operator fun div(divisor: BigDecimal): BigDecimal

Returns a BigDecimal whose value is (this / divisor), and whose preferred _scale is (this._scale() - divisor._scale()); if the exact quotient cannot be represented (because it has a non-terminating decimal expansion) an ArithmeticException is thrown.

abstract fun div(divisor: BigDecimal, mc: MathContext): BigDecimal?

Returns a BigDecimal whose value is (this / divisor), with rounding according to the context settings.

Link copied to clipboard

Returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

Returns a two-element BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.

Link copied to clipboard

Returns a BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down. The preferred _scale of the result is (this._scale() - divisor._scale()).

Returns a BigDecimal whose value is the integer part of (this / divisor). Since the integer part of the exact quotient does not depend on the rounding mode, the rounding mode does not affect the values returned by this method. The preferred _scale of the result is (this._scale() - divisor._scale()). An ArithmeticException is thrown if the integer part of the exact quotient needs more than mc._precision digits.

Link copied to clipboard
abstract fun max(val: BigDecimal): BigDecimal

Returns the maximum of this BigDecimal and val.

Link copied to clipboard
abstract fun min(val: BigDecimal): BigDecimal

Returns the minimum of this BigDecimal and val.

Link copied to clipboard
abstract operator fun minus(subtrahend: BigDecimal): BigDecimal

Returns a BigDecimal whose value is (this - subtrahend), and whose _scale is max(this._scale(), subtrahend._scale()).

abstract fun minus(subtrahend: BigDecimal, mc: MathContext): BigDecimal

Returns a BigDecimal whose value is (this - subtrahend), with rounding according to the context settings.

Link copied to clipboard
abstract fun movePointLeft(n: Int): BigDecimal

Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left. If n is non-negative, the call merely adds n to the _scale. If n is negative, the call is equivalent to movePointRight(-n). The BigDecimal returned by this call has value (this 10<sup>-n</sup>) and _scale max(this._scale()+n, 0).

Link copied to clipboard
abstract fun movePointRight(n: Int): BigDecimal

Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right. If n is non-negative, the call merely subtracts n from the _scale. If n is negative, the call is equivalent to movePointLeft(-n). The BigDecimal returned by this call has value (this 10<sup>n</sup>) and _scale max(this._scale()-n, 0).

Link copied to clipboard
abstract operator fun plus(augend: BigDecimal?): BigDecimal

Returns a BigDecimal whose value is (this + augend), and whose _scale is max(this._scale(), augend._scale()).

abstract fun plus(augend: BigDecimal?, mc: MathContext): BigDecimal

Returns a BigDecimal whose value is (this + augend), with rounding according to the context settings.

Link copied to clipboard
abstract infix fun pow(n: Int): BigDecimal

Returns a BigDecimal whose value is (this<sup>n</sup>), The power is computed exactly, to unlimited _precision.

abstract fun pow(n: Int, mc: MathContext): BigDecimal?

Returns a BigDecimal whose value is (this<sup>n</sup>). The current implementation uses the core algorithm defined in ANSI standard X3.274-1996 with rounding according to the context settings. In general, the returned numerical value is within two ulps of the exact numerical value for the chosen _precision. Note that future releases may use a different algorithm with a decreased allowable error bound and increased allowable exponent range.

Link copied to clipboard
abstract operator fun rem(divisor: BigDecimal): BigDecimal

Returns a BigDecimal whose value is (this % divisor).

abstract fun rem(divisor: BigDecimal, mc: MathContext): BigDecimal

Returns a BigDecimal whose value is (this % divisor), with rounding according to the context settings. The MathContext settings affect the implicit div used to compute the remainder. The remainder computation itself is by definition exact. Therefore, the remainder may contain more than mc.getPrecision() digits.

Link copied to clipboard
abstract fun round(mc: MathContext): BigDecimal?

Returns a BigDecimal rounded according to the MathContext settings. If the _precision setting is 0 then no rounding takes place.

Link copied to clipboard
abstract fun scaleByPowerOfTen(n: Int): BigDecimal

Returns a BigDecimal whose numerical value is equal to (this * 10n). The _scale of the result is (this._scale() - n).

Link copied to clipboard
abstract fun setScale(newScale: Int): BigDecimal

Returns a BigDecimal whose _scale is the specified value, and whose value is numerically equal to this BigDecimal's. Throws an ArithmeticException if this is not possible.

abstract fun setScale(newScale: Int, roundingMode: Int): BigDecimal
abstract fun setScale(newScale: Int, roundingMode: RoundingMode): BigDecimal

Returns a BigDecimal whose _scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal's unscaled value by the appropriate power of ten to maintain its overall value. If the _scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Link copied to clipboard
abstract fun sqrt(mc: MathContext = MathContext()): BigDecimal

Returns an approximation to the square root of this with rounding according to the context settings.

Link copied to clipboard

Returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from the BigDecimal value 600.0, which has [BigInteger, _scale] components equals to [6000, 1], yields 6E2 with [BigInteger, scale] components equals to [6, -2]. If this BigDecimal is numerically equal to zero, then BigDecimal.ZERO is returned.

Link copied to clipboard
abstract operator fun times(multiplicand: BigDecimal?): BigDecimal

Returns a BigDecimal whose value is (this multiplicand), and whose _scale is (this._scale() + multiplicand._scale()).

abstract fun times(multiplicand: BigDecimal, mc: MathContext): BigDecimal

Returns a BigDecimal whose value is (this multiplicand), with rounding according to the context settings.

Link copied to clipboard
abstract fun toBigInteger(): BigInteger

Converts this BigDecimal to a BigInteger. This conversion is analogous to the narrowing primitive conversion from double to long as defined in The Java Language Specification: any fractional part of this BigDecimal will be discarded. Note that this conversion can lose information about the _precision of the BigDecimal value.

Link copied to clipboard

Converts this BigDecimal to a BigInteger, checking for lost information. An exception is thrown if this BigDecimal has a nonzero fractional part.

Link copied to clipboard
abstract fun toByte(): Byte
Link copied to clipboard
abstract fun toByteExact(): Byte

Converts this BigDecimal to a byte, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a byte result then an ArithmeticException is thrown.

Link copied to clipboard
abstract fun toChar(): Char
Link copied to clipboard
abstract fun toDouble(): Double

Converts this BigDecimal to a double. This conversion is similar to the narrowing primitive conversion from double to float as defined in The Java Language Specification: if this BigDecimal has too great a magnitude represent as a double, it will be converted to Double.NEGATIVE_INFINITY or as appropriate. Note that even when the return value is finite, this conversion can lose information about the _precision of the BigDecimal value.

Link copied to clipboard
abstract fun toEngineeringString(): String

Returns a string representation of this BigDecimal, using engineering notation if an exponent is needed.

Link copied to clipboard
abstract fun toFloat(): Float

Converts this BigDecimal to a float. This conversion is similar to the narrowing primitive conversion from double to float as defined in The Java Language Specification: if this BigDecimal has too great a magnitude to represent as a float, it will be converted to Float.NEGATIVE_INFINITY or as appropriate. Note that even when the return value is finite, this conversion can lose information about the _precision of the BigDecimal value.

Link copied to clipboard
abstract fun toInt(): Int

Converts this BigDecimal to an int. This conversion is analogous to the narrowing primitive conversion from double to short as defined in The Java Language Specification: any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big to fit in an int, only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude and _precision of this BigDecimal value as well as return a result with the opposite sign.

Link copied to clipboard
abstract fun toIntExact(): Int

Converts this BigDecimal to an int, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for an int result then an ArithmeticException is thrown.

Link copied to clipboard
Link copied to clipboard
abstract fun toLong(): Long

Converts this BigDecimal to a long. This conversion is analogous to the narrowing primitive conversion from double to short as defined in The Java Language Specification: any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big to fit in a long, only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude and _precision of this BigDecimal value as well as return a result with the opposite sign.

Link copied to clipboard
abstract fun toLongExact(): Long

Converts this BigDecimal to a long, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a long result then an ArithmeticException is thrown.

Link copied to clipboard
abstract fun toPlainString(): String

Returns a string representation of this BigDecimal without an exponent field. For values with a positive _scale, the number of digits to the right of the decimal point is used to indicate _scale. For values with a zero or negative _scale, the resulting string is generated as if the value were converted to a numerically equal value with zero _scale and as if all the trailing zeros of the zero _scale value were present in the result.

Link copied to clipboard
abstract fun toShort(): Short
Link copied to clipboard
abstract fun toShortExact(): Short

Converts this BigDecimal to a short, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown.

Link copied to clipboard
abstract fun ulp(): BigDecimal

Returns the size of an ulp, a unit in the last place, of this BigDecimal. An ulp of a nonzero BigDecimal value is the positive distance between this value and the BigDecimal value next larger in magnitude with the same number of digits. An ulp of a zero value is numerically equal to 1 with the _scale of this. The result is stored with the same _scale as this so the result for zero and nonzero values is equal to [1, this._scale()].

Link copied to clipboard
abstract operator fun unaryMinus(): BigDecimal

Returns a BigDecimal whose value is (-this), and whose _scale is this._scale().

abstract fun unaryMinus(mc: MathContext): BigDecimal?

Returns a BigDecimal whose value is (-this), with rounding according to the context settings.

Link copied to clipboard
abstract operator fun unaryPlus(): BigDecimal

Returns a BigDecimal whose value is (+this), and whose _scale is this._scale().

abstract fun unaryPlus(mc: MathContext): BigDecimal?

Returns a BigDecimal whose value is (+this), with rounding according to the context settings.