BigDecimal

class BigDecimal : BigNumber<BigDecimal> , CommonBigNumberOperations<BigDecimal> , NarrowingOperations<BigDecimal> , Comparable<Any>

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
Created by Ugljesa Jovanovic ugljesa.jovanovic@ionspin.com on 23-Mar-2019

Types

Link copied to clipboard

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

precisionLimit is zero if precision unlimited. Otherwise returns DecimalMode.decimalPrecision.

Link copied to clipboard
Link copied to clipboard
val scale: Long
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun abs(): BigDecimal

Return Absolute value

Link copied to clipboard
open override fun add(other: BigDecimal): BigDecimal

Add two BigDecimal and return result in a new instance of BigDecimal. Default decimal mode will be used.

fun add(other: BigDecimal, decimalMode: DecimalMode? = null): BigDecimal

Add two BigDecimal and return result in a new instance of BigDecimal.

Link copied to clipboard
open override fun byteValue(exactRequired: Boolean): Byte

Convert the current value to Byte.

Link copied to clipboard

Return this truncated by using ceil rounding

Link copied to clipboard
fun compare(other: BigDecimal): Int

Compare to other BigDecimal

Link copied to clipboard
open operator override fun compareTo(other: Any): Int
Link copied to clipboard
fun copy(significand: BigInteger = this.significand, exponent: Long = this.exponent, decimalMode: DecimalMode? = this.decimalMode): BigDecimal

Creates a copy of this BigDecimal with some different elements (significand/exponent/decimalMode)

Link copied to clipboard

Decrement by one

Link copied to clipboard
open operator fun div(byte: Byte): BigDecimal
open operator fun div(int: Int): BigDecimal
open operator fun div(long: Long): BigDecimal
open operator fun div(short: Short): BigDecimal
open operator override fun div(other: BigDecimal): BigDecimal
Link copied to clipboard
open override fun divide(other: BigDecimal): BigDecimal

fun divide(other: BigDecimal, decimalMode: DecimalMode? = null): BigDecimal

Divide two BigDecimal and return result in a new instance of BigDecimal

Link copied to clipboard

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

Link copied to clipboard
Link copied to clipboard
open override fun doubleValue(exactRequired: Boolean): Double

Narrow to a double.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun floatValue(exactRequired: Boolean): Float

Narrow to a float.

Link copied to clipboard

Return this truncated by using floor rounding

Link copied to clipboard
Link copied to clipboard
open override fun getInstance(): BigDecimal
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Incerement by one

Link copied to clipboard
open override fun intValue(exactRequired: Boolean): Int

Convert the current value to Int.

Link copied to clipboard
Link copied to clipboard
open override fun isZero(): Boolean
Link copied to clipboard
open override fun longValue(exactRequired: Boolean): Long

Convert the current value to Long.

Link copied to clipboard
open operator fun minus(byte: Byte): BigDecimal
open operator fun minus(int: Int): BigDecimal
open operator fun minus(long: Long): BigDecimal
open operator fun minus(short: Short): BigDecimal
open operator override fun minus(other: BigDecimal): BigDecimal
Link copied to clipboard

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.

Link copied to clipboard
open override fun multiply(other: BigDecimal): BigDecimal

Multiply two BigDecimal and return result in a new instance of BigDecimal Default decimal mode will be used

fun multiply(other: BigDecimal, decimalMode: DecimalMode? = null): BigDecimal

Multiply two BigDecimal and return result in a new instance of BigDecimal

Link copied to clipboard
open override fun negate(): BigDecimal

Negate this BigDecimal

Link copied to clipboard
open override fun numberOfDecimalDigits(): Long

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)

Link copied to clipboard
open operator fun plus(byte: Byte): BigDecimal
open operator fun plus(int: Int): BigDecimal
open operator fun plus(long: Long): BigDecimal
open operator fun plus(short: Short): BigDecimal
open operator override fun plus(other: BigDecimal): BigDecimal
Link copied to clipboard
open override fun pow(exponent: Int): BigDecimal

Exponentiate this BigDecimal by some exponent

open override fun pow(exponent: Long): BigDecimal

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.

Link copied to clipboard
open operator fun rem(byte: Byte): BigDecimal

Remainder of integer division operation. Remainder has same sign as dividend.

open operator fun rem(int: Int): BigDecimal
open operator fun rem(long: Long): BigDecimal
open operator fun rem(short: Short): BigDecimal

Remainder of integer division operation. Remainder has same sign as dividend

open operator override fun rem(other: BigDecimal): BigDecimal

Remainder of integer division operation. Returns the least absolute remainder (remainder has same sign as dividend)

Link copied to clipboard
open override fun remainder(other: BigDecimal): BigDecimal

Remainder of integer division on this bigDecimal. If there is no rounding mode defined in decimal mode #RoundingMode.FLOOR will be used

Link copied to clipboard
Link copied to clipboard

Round using specific DecimalMode and return rounded instance. This is applied only to significand.

Link copied to clipboard
fun roundToDigitPosition(digitPosition: Long, roundingMode: RoundingMode = this.roundingMode): BigDecimal

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.

Link copied to clipboard

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.

Link copied to clipboard
fun scale(scale: Long): BigDecimal
Link copied to clipboard
open override fun secureOverwrite()

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.

Link copied to clipboard
open override fun shortValue(exactRequired: Boolean): Short

Convert the current value to Short.

Link copied to clipboard
open override fun signum(): Int

Signum function

Link copied to clipboard
open override fun subtract(other: BigDecimal): BigDecimal

Subtract two BigDecimal and return result in a new instance of BigDecimal. Default decimal mode will be used

fun subtract(other: BigDecimal, decimalMode: DecimalMode? = null): BigDecimal

Subtract two BigDecimal and return result in a new instance of BigDecimal

Link copied to clipboard
open operator fun times(byte: Byte): BigDecimal
open operator fun times(int: Int): BigDecimal
open operator fun times(long: Long): BigDecimal
open operator fun times(short: Short): BigDecimal
open operator override fun times(other: BigDecimal): BigDecimal
Link copied to clipboard
operator fun Long.times(char: Char): String
Link copied to clipboard

Convert to big integer by truncating

Link copied to clipboard

Created by Ugljesa Jovanovic ugljesa.jovanovic@ionspin.com on 24-Mar-2019

Link copied to clipboard

Convenience method matching Java BigDecimal, same functionality as toStringExpanded

Link copied to clipboard
open override fun toString(): String

Return this BigDecimal in scientific notation i.e. 1.23E+9

open override fun toString(base: Int): String
Link copied to clipboard

Return this big decimal in expanded notation. i.e. 123000000 for 1.23E+9 or 0.00000000123 for 1.23E-9

Link copied to clipboard
open override fun ubyteValue(exactRequired: Boolean): UByte

Convert the current value to UByte.

Link copied to clipboard
open override fun uintValue(exactRequired: Boolean): UInt

Convert the current value to UInt.

Link copied to clipboard
open override fun ulongValue(exactRequired: Boolean): ULong

Convert the current value to ULong.

Link copied to clipboard
open operator override fun unaryMinus(): BigDecimal

Returns a new negated instance

Link copied to clipboard
open override fun ushortValue(exactRequired: Boolean): UShort

Convert the current value to UShort.