Money

Represents a monetary value.

Money is an implementation of the pattern with the same name and provides methods for mathematical operations, allocation, and currency exchange rate. The Money type is intended to be used as a base data type.

Types

Link copied to clipboard
object Factory

A Money factory.

Properties

Link copied to clipboard

The monetary amount.

Link copied to clipboard

The monetary currency.

Link copied to clipboard

true if it has rounding support.

Link copied to clipboard

true if the monetary amount is negative.

Link copied to clipboard

true if the monetary amount is negative or zero.

Link copied to clipboard

true if the monetary amount is not zero.

Link copied to clipboard

true if the monetary amount is positive.

Link copied to clipboard

true if the monetary amount is positive or zero.

Link copied to clipboard

true if the monetary amount is zero.

Functions

Link copied to clipboard

Allocates a Money according to the by parameter:

fun Money.allocate(vararg ratios: Percentage): Result
infix fun Money.allocate(ratios: List<Percentage>): Result

Allocates a Money in ratios. Example:

infix fun Money.allocate(parts: Int): Result

Allocates a Money in equal parts. Example:

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

Decreases this Money by the given Percentage.

Link copied to clipboard
operator fun div(by: Number): Money

Divides this Money.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
infix fun Money.exchange(rate: Money): Money

Converts a Money to another currency by the given exchange rate. Calculations using the resulting Money will be rounded with the strategy of the given rate object.

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

Increases this Money by the given Percentage.

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

Subtracts this Money with a second one.

Link copied to clipboard

Creates a Money based on this instance with the NoRounding strategy.

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

Sums this Money with a second one.

Link copied to clipboard
infix fun ratio(other: Money): Double

Calculates the ratio between this Money and a second one.

Link copied to clipboard
fun round(): Money

Rounds the Money using the current rounding strategy.

infix fun round(rounding: Rounding): Money

Rounds the Money using the specified rounding strategy.

infix fun round(mode: RoundingMode): Money

Rounds the Money using the specified mode.

Link copied to clipboard

Creates a Money based on this instance but with the monetary amount set to the smallest unit of the currency. Example:

Link copied to clipboard
operator fun times(by: Number): Money

Multiplies this Money.

Link copied to clipboard
operator fun Money.times(by: Percentage): Money

Multiplies this Money by the given Percentage.

Link copied to clipboard

Returns a string representation of the object, including all public properties.

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

Creates a Money by negating this instance.

Link copied to clipboard
operator fun unaryPlus(): Money

Creates a positive Money based on this instance.

Link copied to clipboard
infix fun with(rounding: Rounding): Money

Creates a Money based on this instance one using the specified rounding strategy.

infix fun with(mode: RoundingMode): Money

Creates a Money based on this instance but with the specified mode to configure the rounding strategy.

Link copied to clipboard

Creates a Money based on this instance but with the monetary amount set to zero. Example: