Money

world.money.money$package.Money
object Money

Factories, arithmetic, rounding boundaries, and allocation for Money.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Money.type

Members list

Type members

Classlikes

sealed abstract class Unallocatable extends WorldError

Weights that admit no allocation: empty, negative, or summing to nothing.

Weights that admit no allocation: empty, negative, or summing to nothing.

Attributes

Companion
object
Supertypes
class WorldError
class TypedError
trait NoStackTrace
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes
object Unallocatable
case object Unallocatable extends Unallocatable

Attributes

Companion
class
Supertypes
trait Singleton
trait Product
trait Mirror
trait Product
trait Equals
class WorldError
class TypedError
trait NoStackTrace
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
final case class Value(currency: Currency, amount: BigDecimal)

The storage and wire form: the currency explicit beside its amount. Re-enter the typed world by binding the currency, as v match { case Money.Value(c, a) => c(a) }.

The storage and wire form: the currency explicit beside its amount. Re-enter the typed world by binding the currency, as v match { case Money.Value(c, a) => c(a) }.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Value

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Value.type

Value members

Concrete methods

def add[C <: Currency & Singleton](m: Money[C], n: Money[C]): Money[C]
def allocate[C <: Currency & Singleton](m: Money[C], weights: Seq[Int]): Either[Unallocatable, Vector[Money[C]]]

Splits the exact amount by integer weights at its own scale.

Splits the exact amount by integer weights at its own scale.

Attributes

def allocate[C <: Currency & Singleton](m: Money[C], weights: Seq[Ratio]): Either[Unallocatable, Vector[Money[C]]]

Allocation by exact ratio weights.

Allocation by exact ratio weights.

Attributes

def amortisation[C <: Currency & Singleton](m: Money[C], rate: Ratio, periods: Int, mode: Rounding)(using ValueOf[C]): Either[Undefined, Vector[Instalment[C]]]

The printed schedule behind the annuity.

The printed schedule behind the annuity.

Attributes

def amortisation[C <: Currency & Singleton](m: Money[C], rate: Ratio, periods: Int, scale: Int, mode: Rounding): Either[Undefined, Vector[Instalment[C]]]
def annuity[C <: Currency & Singleton](m: Money[C], rate: Ratio, periods: Int, mode: Rounding)(using ValueOf[C]): Either[Undefined, Money[C]]

The level payment amortising this principal on the reducing balance.

The level payment amortising this principal on the reducing balance.

Attributes

def annuity[C <: Currency & Singleton](m: Money[C], rate: Ratio, periods: Int, scale: Int, mode: Rounding): Either[Undefined, Money[C]]
def apply[C <: Currency & Singleton](amount: BigDecimal): Money[C]
def canonical(v: Value): Value

The deterministic rendering a ledger key, an audit hash, or a deduplication compares: trailing zeros stripped, then padded to the currency's minor unit where it has one, so anything finer survives.

The deterministic rendering a ledger key, an audit hash, or a deduplication compares: trailing zeros stripped, then padded to the currency's minor unit where it has one, so anything finer survives.

Attributes

def cash[C <: Currency & Singleton](m: Money[C], t: Territory)(using ValueOf[C]): Money[C]

Rounds to the cash increment the territory's recorded practice sets for this currency.

Rounds to the cash increment the territory's recorded practice sets for this currency.

Attributes

def cash[C <: Currency & Singleton](m: Money[C], t: Territory, mode: Rounding)(using ValueOf[C]): Money[C]
def convert[C <: Currency & Singleton, T <: Currency & Singleton](m: Money[C], rate: Rate[C, T]): Money[T]
def divided[C <: Currency & Singleton](m: Money[C], k: BigDecimal, scale: Int, mode: Rounding): Either[Undefined, Money[C]]
def greaterOrEqual[C <: Currency & Singleton](m: Money[C], n: Money[C]): Boolean
def greaterThan[C <: Currency & Singleton](m: Money[C], n: Money[C]): Boolean
def lessOrEqual[C <: Currency & Singleton](m: Money[C], n: Money[C]): Boolean
def lessThan[C <: Currency & Singleton](m: Money[C], n: Money[C]): Boolean
def margin[C <: Currency & Singleton](m: Money[C], p: Percent, mode: Rounding)(using ValueOf[C]): Either[Undefined, Money[C]]

The selling price at a margin, rounded at the currency's scale.

The selling price at a margin, rounded at the currency's scale.

Attributes

def margin[C <: Currency & Singleton](m: Money[C], p: Percent, scale: Int, mode: Rounding): Either[Undefined, Money[C]]
def markup[C <: Currency & Singleton](m: Money[C], p: Percent): Money[C]

The selling price at a markup over this cost.

The selling price at a markup over this cost.

Attributes

def max[C <: Currency & Singleton](m: Money[C], n: Money[C]): Money[C]
def min[C <: Currency & Singleton](m: Money[C], n: Money[C]): Money[C]
def multiply[C <: Currency & Singleton](m: Money[C], k: BigDecimal): Money[C]
def multiply[C <: Currency & Singleton](m: Money[C], k: Int): Money[C]
def rounded[C <: Currency & Singleton](m: Money[C], mode: Rounding)(using c: ValueOf[C]): Money[C]

Rounds to the currency's minor unit. Identity for currencies without one (metals, special codes), whose amounts have no legal-tender scale; use rounded(scale, mode) to impose one.

Rounds to the currency's minor unit. Identity for currencies without one (metals, special codes), whose amounts have no legal-tender scale; use rounded(scale, mode) to impose one.

Attributes

def rounded[C <: Currency & Singleton](m: Money[C], scale: Int, mode: Rounding): Money[C]
def scaled[C <: Currency & Singleton](m: Money[C], r: Ratio, mode: Rounding)(using ValueOf[C]): Money[C]

Scales by an exact ratio, rounded at the currency's scale.

Scales by an exact ratio, rounded at the currency's scale.

Attributes

def scaled[C <: Currency & Singleton](m: Money[C], r: Ratio, scale: Int, mode: Rounding): Money[C]
def split[C <: Currency & Singleton](m: Money[C], parts: Int): Either[Unallocatable, Vector[Money[C]]]
def subtract[C <: Currency & Singleton](m: Money[C], n: Money[C]): Money[C]
def zero[C <: Currency & Singleton]: Money[C]

Givens

Givens

given given_CanEqual_Money_Money: [C <: Currency & Singleton] => CanEqual[Money[C], Money[C]]
given given_Ordering_Money: [C <: Currency & Singleton] => Ordering[Money[C]]

Extensions

Extensions

extension [C <: Currency & Singleton](m: Money[C])
def *(k: BigDecimal): Money[C]
def *(k: Int): Money[C]
inline def *(k: Double): Money[C]
def +(n: Money[C]): Money[C]
def -(n: Money[C]): Money[C]
def <(n: Money[C]): Boolean
def <=(n: Money[C]): Boolean
def >(n: Money[C]): Boolean
def >=(n: Money[C]): Boolean
def abs: Money[C]
def allocate(weights: Seq[Int]): Either[Unallocatable, Vector[Money[C]]]

Splits the exact amount by integer weights at its own scale: the parts always sum to the whole, a zero weight receives zero, and the remainder goes to the largest fractional shares (ties to the earliest). Round first to allocate legal tender.

Splits the exact amount by integer weights at its own scale: the parts always sum to the whole, a zero weight receives zero, and the remainder goes to the largest fractional shares (ties to the earliest). Round first to allocate legal tender.

Attributes

def allocate(weights: Seq[Ratio]): Either[Unallocatable, Vector[Money[C]]]

Allocation by exact ratio weights - proportional-to-balances splits and the like.

Allocation by exact ratio weights - proportional-to-balances splits and the like.

Attributes

def amortisation(rate: Ratio, periods: Int, mode: Rounding)(using c: ValueOf[C]): Either[Undefined, Vector[Instalment[C]]]

The printed schedule behind annuity: each instalment's interest is the period's opening balance at rate, its principal the payment's remainder, and the last instalment absorbs the rounding residual, so the balance closes at exactly zero and the principals sum to exactly this amount. Unlike allocate, which spreads the remainder, a schedule closes on its final row. Undefined as annuity.

The printed schedule behind annuity: each instalment's interest is the period's opening balance at rate, its principal the payment's remainder, and the last instalment absorbs the rounding residual, so the balance closes at exactly zero and the principals sum to exactly this amount. Unlike allocate, which spreads the remainder, a schedule closes on its final row. Undefined as annuity.

Attributes

def amortisation(rate: Ratio, periods: Int, scale: Int, mode: Rounding): Either[Undefined, Vector[Instalment[C]]]

The same at an explicit scale.

The same at an explicit scale.

Attributes

def amount: BigDecimal

The exact amount, at whatever scale arithmetic has produced.

The exact amount, at whatever scale arithmetic has produced.

Attributes

def annuity(rate: Ratio, periods: Int, mode: Rounding)(using c: ValueOf[C]): Either[Undefined, Money[C]]

The level payment amortising this principal over periods at the periodic rate rate on the reducing balance, exact until the currency-scale rounding by mode. A zero rate degenerates to the equal split; non-positive periods and a degenerate rate are Undefined.

The level payment amortising this principal over periods at the periodic rate rate on the reducing balance, exact until the currency-scale rounding by mode. A zero rate degenerates to the equal split; non-positive periods and a degenerate rate are Undefined.

Named rather than left to the caller because flat-rate quoting is a plain multiplication and the two are a costly confusion.

Attributes

def annuity(rate: Ratio, periods: Int, scale: Int, mode: Rounding): Either[Undefined, Money[C]]

The same at an explicit scale - schedule analysis below the posting scale, and the controlled form for currencies without a minor unit.

The same at an explicit scale - schedule analysis below the posting scale, and the controlled form for currencies without a minor unit.

Attributes

def cash(t: Territory)(using c: ValueOf[C]): Money[C]

Rounds to the cash increment the territory's recorded practice sets for this currency. Cash practice is the jurisdiction's fact, never the currency's: one euro rounds to five cents by statute in Finland, by voluntary agreement in the Netherlands, and not at all in Germany. The caller names the territory; one recording no practice for this currency falls back to minor-unit half-even.

Rounds to the cash increment the territory's recorded practice sets for this currency. Cash practice is the jurisdiction's fact, never the currency's: one euro rounds to five cents by statute in Finland, by voluntary agreement in the Netherlands, and not at all in Germany. The caller names the territory; one recording no practice for this currency falls back to minor-unit half-even.

Attributes

def cash(t: Territory, mode: Rounding)(using c: ValueOf[C]): Money[C]

Cash rounding with the midpoint mode imposed at the call site.

Cash rounding with the midpoint mode imposed at the call site.

Attributes

def convert[T <: Currency & Singleton](rate: Rate[C, T]): Money[T]

Converts through an exchange rate, exactly; rounding remains the caller's boundary.

Converts through an exchange rate, exactly; rounding remains the caller's boundary.

Attributes

def currency(using c: ValueOf[C]): Currency
def divided(k: BigDecimal, scale: Int, mode: Rounding): Either[Undefined, Money[C]]
def isZero: Boolean
def margin(p: Percent, mode: Rounding)(using c: ValueOf[C]): Either[Undefined, Money[C]]

The selling price at a margin - cost / (1 - margin) - rounded at the currency's scale by mode (the quotient need not terminate). Undefined at a 100% margin.

The selling price at a margin - cost / (1 - margin) - rounded at the currency's scale by mode (the quotient need not terminate). Undefined at a 100% margin.

Attributes

def margin(p: Percent, scale: Int, mode: Rounding): Either[Undefined, Money[C]]

The same at an explicit scale - sub-minor pricing (fuel-grade precision), and the controlled form for currencies without a minor unit.

The same at an explicit scale - sub-minor pricing (fuel-grade precision), and the controlled form for currencies without a minor unit.

Attributes

def markup(p: Percent): Money[C]

The selling price at a markup over this cost, cost * (1 + markup), exact. Named apart from margin, which divides where this multiplies.

The selling price at a markup over this cost, cost * (1 + markup), exact. Named apart from margin, which divides where this multiplies.

Attributes

def max(n: Money[C]): Money[C]
def min(n: Money[C]): Money[C]
def minor(using c: ValueOf[C]): Option[Long]

The amount in minor units, when exactly representable at the currency's scale.

The amount in minor units, when exactly representable at the currency's scale.

Attributes

def rounded(mode: Rounding)(using ValueOf[C]): Money[C]
def rounded(scale: Int, mode: Rounding): Money[C]
def scaled(r: Ratio, mode: Rounding)(using c: ValueOf[C]): Money[C]

Scales by an exact ratio - a day-count fraction, an apportionment share - rounded at the currency's scale by mode (the quotient need not terminate, so the boundary is named).

Scales by an exact ratio - a day-count fraction, an apportionment share - rounded at the currency's scale by mode (the quotient need not terminate, so the boundary is named).

Attributes

def scaled(r: Ratio, scale: Int, mode: Rounding): Money[C]

The same scaling at an explicit scale: sub-minor-unit accrual (a ledger carries interest at four places before posting), and the controlled form for currencies that record no minor unit, which the currency-scale form rounds to whole units.

The same scaling at an explicit scale: sub-minor-unit accrual (a ledger carries interest at four places before posting), and the controlled form for currencies that record no minor unit, which the currency-scale form rounds to whole units.

Attributes

def signum: Int
def split(parts: Int): Either[Unallocatable, Vector[Money[C]]]

Splits into parts equal shares; equivalent to allocating unit weights.

Splits into parts equal shares; equivalent to allocating unit weights.

Attributes

def unary_-: Money[C]
def value(using c: ValueOf[C]): Value
extension (v: Value)