world.money

package world.money

Members list

Type members

Classlikes

final case class Money[C <: Currency]

A type-safe representation of a monetary amount, parameterised by its currency.

A type-safe representation of a monetary amount, parameterised by its currency.

This is a pure data aggregate combining a numeric world.money.currency.CurrencyValue with a specific Currency C. This design ensures that arithmetic operations between different currencies are prevented at compile time, eliminating a common source of errors.

All operations on Money instances are provided as extension methods in the companion object, maintaining strict separation of data from behaviour.

===How to Create Money Instances===

There are two primary ways to create an instance of Money.

  1. Currency-Specific Syntax (Recommended): The preferred method for creating amounts of a known currency is to use the generated syntax extensions. This provides a clean, readable, and type-safe DSL.
import world.money.*

// Creates a Money instance with the type Money[Currencies.KES.type]
val tenShillings = 10.KES
val fiftyRiyals = 50.50.OMR
  1. Generic Factory Money.apply: For generic programming, where the currency type C is a type parameter, you can use the companion object's apply method. This requires a ValueOf[C] to be available in the implicit scope to provide the runtime currency object.
import world.money.currency.{Currency, Currencies}

def createGenericMoney[C <: Currency](value: BigDecimal)(using ValueOf[C]): Money[C] = {
Money(value) // Uses Money.apply[C](...)
}

val genericKES = createGenericMoney[Currencies.KES.type](100)

Type parameters

C

The singleton type of the currency, constrained to be a subtype of world.money.currency.Currency.

Value parameters

currency

A ValueOf instance that provides the currency object at runtime.

value

The numeric value of the amount.

Attributes

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

Provides factory methods for creating Money instances

Provides factory methods for creating Money instances

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Money.type
object errors

Defines the hierarchy of errors for money-related operations.

Defines the hierarchy of errors for money-related operations.

This object provides a central location for all error types that can be returned by the library, including those related to arithmetic, formatting, currency validation, and currency conversion.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
errors.type

Extensions

Extensions

extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def AED: Money[AED.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def AFN: Money[AFN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ALL: Money[ALL.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def AMD: Money[AMD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def AOA: Money[AOA.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ARS: Money[ARS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def AUD: Money[AUD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def AWG: Money[AWG.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def AZN: Money[AZN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BAM: Money[BAM.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BBD: Money[BBD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BDT: Money[BDT.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BGN: Money[BGN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BHD: Money[BHD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BIF: Money[BIF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BMD: Money[BMD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BND: Money[BND.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BOB: Money[BOB.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BOV: Money[BOV.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BRL: Money[BRL.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BSD: Money[BSD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BTN: Money[BTN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BWP: Money[BWP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BYN: Money[BYN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def BZD: Money[BZD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CAD: Money[CAD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CDF: Money[CDF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CHE: Money[CHE.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CHF: Money[CHF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CHW: Money[CHW.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CLF: Money[CLF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CLP: Money[CLP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CNY: Money[CNY.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def COP: Money[COP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def COU: Money[COU.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CRC: Money[CRC.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CUP: Money[CUP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CVE: Money[CVE.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def CZK: Money[CZK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def DJF: Money[DJF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def DKK: Money[DKK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def DOP: Money[DOP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def DZD: Money[DZD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def EGP: Money[EGP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ERN: Money[ERN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ETB: Money[ETB.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def EUR: Money[EUR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def FJD: Money[FJD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def FKP: Money[FKP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GBP: Money[GBP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GEL: Money[GEL.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GHS: Money[GHS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GIP: Money[GIP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GMD: Money[GMD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GNF: Money[GNF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GTQ: Money[GTQ.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def GYD: Money[GYD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def HKD: Money[HKD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def HNL: Money[HNL.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def HTG: Money[HTG.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def HUF: Money[HUF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def IDR: Money[IDR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ILS: Money[ILS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def INR: Money[INR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def IQD: Money[IQD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def IRR: Money[IRR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ISK: Money[ISK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def JMD: Money[JMD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def JOD: Money[JOD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def JPY: Money[JPY.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KES: Money[KES.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KGS: Money[KGS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KHR: Money[KHR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KMF: Money[KMF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KPW: Money[KPW.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KRW: Money[KRW.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KWD: Money[KWD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KYD: Money[KYD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def KZT: Money[KZT.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def LAK: Money[LAK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def LBP: Money[LBP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def LKR: Money[LKR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def LRD: Money[LRD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def LSL: Money[LSL.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def LYD: Money[LYD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MAD: Money[MAD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MDL: Money[MDL.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MGA: Money[MGA.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MKD: Money[MKD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MMK: Money[MMK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MNT: Money[MNT.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MOP: Money[MOP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MRU: Money[MRU.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MUR: Money[MUR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MVR: Money[MVR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MWK: Money[MWK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MXN: Money[MXN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MXV: Money[MXV.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MYR: Money[MYR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def MZN: Money[MZN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def NAD: Money[NAD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def NGN: Money[NGN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def NIO: Money[NIO.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def NOK: Money[NOK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def NPR: Money[NPR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def NZD: Money[NZD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def OMR: Money[OMR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def PAB: Money[PAB.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def PEN: Money[PEN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def PGK: Money[PGK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def PHP: Money[PHP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def PKR: Money[PKR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def PLN: Money[PLN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def PYG: Money[PYG.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def QAR: Money[QAR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def RON: Money[RON.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def RSD: Money[RSD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def RUB: Money[RUB.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def RWF: Money[RWF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SAR: Money[SAR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SBD: Money[SBD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SCR: Money[SCR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SDG: Money[SDG.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SEK: Money[SEK.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SGD: Money[SGD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SHP: Money[SHP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SLE: Money[SLE.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SOS: Money[SOS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SRD: Money[SRD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SSP: Money[SSP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def STN: Money[STN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SVC: Money[SVC.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SYP: Money[SYP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def SZL: Money[SZL.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def THB: Money[THB.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TJS: Money[TJS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TMT: Money[TMT.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TND: Money[TND.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TOP: Money[TOP.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TRY: Money[TRY.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TTD: Money[TTD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TWD: Money[TWD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def TZS: Money[TZS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def UAH: Money[UAH.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def UGX: Money[UGX.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def USD: Money[USD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def USN: Money[USN.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def UYI: Money[UYI.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def UYU: Money[UYU.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def UYW: Money[UYW.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def UZS: Money[UZS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def VED: Money[VED.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def VES: Money[VES.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def VND: Money[VND.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def VUV: Money[VUV.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def WST: Money[WST.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XAF: Money[XAF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XAG: Money[XAG.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XAU: Money[XAU.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XBA: Money[XBA.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XBB: Money[XBB.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XBC: Money[XBC.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XBD: Money[XBD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XCD: Money[XCD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XCG: Money[XCG.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XDR: Money[XDR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XOF: Money[XOF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XPD: Money[XPD.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XPF: Money[XPF.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XPT: Money[XPT.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XSU: Money[XSU.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XTS: Money[XTS.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XUA: Money[XUA.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def XXX: Money[XXX.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def YER: Money[YER.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ZAR: Money[ZAR.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ZMW: Money[ZMW.type]
extension (value: CurrencyValue | BigDecimal | Long | Int | Double)
transparent inline def ZWG: Money[ZWG.type]