Decimal

An exact base-10 number with up to 9 fractional digits.

Decimal is intended for mobility-data prices, fares, rates, and similar values. It stores a single scaled Long and never converts through Double or Float except in the explicitly lossy toDouble and toFloat helpers.

All values use a fixed internal scale of 9 fractional decimal places, so 2.5 and 2.50 are the same number. The representable range is -9223372036.854775808 through 9223372036.854775807.

Types

Link copied to clipboard
object Companion

Constants and parsers for Decimal.

Functions

Link copied to clipboard
fun abs(): Decimal

Returns the absolute value of this number.

Link copied to clipboard
open operator override fun compareTo(other: Decimal): Int

Compares this value to other using exact numeric order.

Link copied to clipboard
operator fun div(other: Decimal): Decimal

Returns the exact quotient of this value and other.

Link copied to clipboard
fun divide(other: Decimal, roundingMode: RoundingMode): Decimal

Divides this value by other and rounds the result to 9 fractional digits using roundingMode.

Link copied to clipboard
operator fun minus(other: Decimal): Decimal

Returns the exact difference of this value and other.

Link copied to clipboard
operator fun plus(other: Decimal): Decimal

Returns the exact sum of this value and other.

Link copied to clipboard
fun round(decimalPlaces: Int, roundingMode: RoundingMode): Decimal

Rounds this value to decimalPlaces fractional digits using roundingMode.

Link copied to clipboard
operator fun times(other: Decimal): Decimal

Returns the exact product of this value and other.

Link copied to clipboard

Converts this value to a Double. This conversion may lose precision.

Link copied to clipboard
fun toFloat(): Float

Converts this value to a Float. This conversion may lose precision.

Link copied to clipboard

Returns this value as an Int if it is an integer in range.

Link copied to clipboard

Returns this value as a Long if it is an integer in range.

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

Returns the shortest ordinary decimal representation that preserves this exact numeric value.

fun toString(decimalPlaces: Int): String

Formats this value with exactly decimalPlaces fractional digits.

Link copied to clipboard
operator fun unaryMinus(): Decimal

Returns the negation of this value.