world.money.currency

Members list

Type members

Classlikes

object CcyCode

Provides factory methods for creating instances of CcyCode.

Provides factory methods for creating instances of CcyCode.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
CcyCode.type
object Currencies

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Currencies.type
trait Currency extends CurrencyDetails

Represents an actively circulating currency.

Represents an actively circulating currency.

All active currencies known to this library are available as predefined singleton objects within the Currencies object.

Attributes

Example
 import world.money.currency.Currencies
val kenyanShilling = Currencies.KES assert(kenyanShilling.name == "Kenyan
Shilling") assert(kenyanShilling.numericCode.value == 404)
assert(kenyanShilling.minorUnit == Some(2)) 
Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
object AED
object AFN
object ALL
object AMD
object AOA
object ARS
object AUD
object AWG
object AZN
object BAM
object BBD
object BDT
object BGN
object BHD
object BIF
object BMD
object BND
object BOB
object BOV
object BRL
object BSD
object BTN
object BWP
object BYN
object BZD
object CAD
object CDF
object CHE
object CHF
object CHW
object CLF
object CLP
object CNY
object COP
object COU
object CRC
object CUP
object CVE
object CZK
object DJF
object DKK
object DOP
object DZD
object EGP
object ERN
object ETB
object EUR
object FJD
object FKP
object GBP
object GEL
object GHS
object GIP
object GMD
object GNF
object GTQ
object GYD
object HKD
object HNL
object HTG
object HUF
object IDR
object ILS
object INR
object IQD
object IRR
object ISK
object JMD
object JOD
object JPY
object KES
object KGS
object KHR
object KMF
object KPW
object KRW
object KWD
object KYD
object KZT
object LAK
object LBP
object LKR
object LRD
object LSL
object LYD
object MAD
object MDL
object MGA
object MKD
object MMK
object MNT
object MOP
object MRU
object MUR
object MVR
object MWK
object MXN
object MXV
object MYR
object MZN
object NAD
object NGN
object NIO
object NOK
object NPR
object NZD
object OMR
object PAB
object PEN
object PGK
object PHP
object PKR
object PLN
object PYG
object QAR
object RON
object RSD
object RUB
object RWF
object SAR
object SBD
object SCR
object SDG
object SEK
object SGD
object SHP
object SLE
object SOS
object SRD
object SSP
object STN
object SVC
object SYP
object SZL
object THB
object TJS
object TMT
object TND
object TOP
object TRY
object TTD
object TWD
object TZS
object UAH
object UGX
object USD
object USN
object UYI
object UYU
object UYW
object UZS
object VED
object VES
object VND
object VUV
object WST
object XAF
object XAG
object XAU
object XBA
object XBB
object XBC
object XBD
object XCD
object XCG
object XDR
object XOF
object XPD
object XPF
object XPT
object XSU
object XTS
object XUA
object XXX
object YER
object ZAR
object ZMW
object ZWG
Show all
object Currency

Provides compile-time access to currency precision (minor unit) information.

Provides compile-time access to currency precision (minor unit) information.

This object exposes a match type PrecisionOf that maps currency singleton types to their precision values, enabling compile-time validation and optimisation of monetary calculations.

The precisionOf method provides a total function that returns precision at compile-time when the currency type is known, falling back to runtime lookup for generic cases.

Attributes

Example
import world.money.currency.{Currencies, Currency}
// Compile-time precision for known currencies
val jpyPrecision = Currency.precisionOf[Currencies.JPY.type]  // 0
val kesPrecision = Currency.precisionOf[Currencies.KES.type]  // 2
val omrPrecision = Currency.precisionOf[Currencies.OMR.type]  // 3
// Works with generic currency types at runtime
def showPrecision[C <: Currency](using ValueOf[C]): Int =
 Currency.precisionOf[C]
Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Currency.type
sealed trait CurrencyDetails extends Product, Serializable

A base trait for all ISO 4217 currency data representations.

A base trait for all ISO 4217 currency data representations.

It defines the fundamental properties shared by all currency entries. Concrete, predefined instances are available in the Currencies$ and HistoricCurrencies$ objects.

Attributes

See also

Currency for actively circulating currencies.

HistoricCurrency for withdrawn currencies.

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
trait Currency
object AED
object AFN
object ALL
object AMD
object AOA
object ARS
object AUD
object AWG
object AZN
object BAM
object BBD
object BDT
object BGN
object BHD
object BIF
object BMD
object BND
object BOB
object BOV
object BRL
object BSD
object BTN
object BWP
object BYN
object BZD
object CAD
object CDF
object CHE
object CHF
object CHW
object CLF
object CLP
object CNY
object COP
object COU
object CRC
object CUP
object CVE
object CZK
object DJF
object DKK
object DOP
object DZD
object EGP
object ERN
object ETB
object EUR
object FJD
object FKP
object GBP
object GEL
object GHS
object GIP
object GMD
object GNF
object GTQ
object GYD
object HKD
object HNL
object HTG
object HUF
object IDR
object ILS
object INR
object IQD
object IRR
object ISK
object JMD
object JOD
object JPY
object KES
object KGS
object KHR
object KMF
object KPW
object KRW
object KWD
object KYD
object KZT
object LAK
object LBP
object LKR
object LRD
object LSL
object LYD
object MAD
object MDL
object MGA
object MKD
object MMK
object MNT
object MOP
object MRU
object MUR
object MVR
object MWK
object MXN
object MXV
object MYR
object MZN
object NAD
object NGN
object NIO
object NOK
object NPR
object NZD
object OMR
object PAB
object PEN
object PGK
object PHP
object PKR
object PLN
object PYG
object QAR
object RON
object RSD
object RUB
object RWF
object SAR
object SBD
object SCR
object SDG
object SEK
object SGD
object SHP
object SLE
object SOS
object SRD
object SSP
object STN
object SVC
object SYP
object SZL
object THB
object TJS
object TMT
object TND
object TOP
object TRY
object TTD
object TWD
object TZS
object UAH
object UGX
object USD
object USN
object UYI
object UYU
object UYW
object UZS
object VED
object VES
object VND
object VUV
object WST
object XAF
object XAG
object XAU
object XBA
object XBB
object XBC
object XBD
object XCD
object XCG
object XDR
object XOF
object XPD
object XPF
object XPT
object XSU
object XTS
object XUA
object XXX
object YER
object ZAR
object ZMW
object ZWG
object ADP
object AFA
object ALK
object ANG
object AOK
object AON
object AOR
object ARA
object ARP
object ARY
object ATS
object AYM
object AZM
object BAD
object BEC
object BEF
object BEL
object BGJ
object BGK
object BGL
object BOP
object BRB
object BRC
object BRE
object BRN
object BRR
object BUK
object BYB
object BYR
object CHC
object CSD
object CSJ
object CSK
object CUC
object CYP
object DDM
object DEM
object ECS
object ECV
object EEK
object ESA
object ESB
object ESP
object FIM
object FRF
object GEK
object GHC
object GHP
object GNE
object GNS
object GQE
object GRD
object GWE
object GWP
object HRD
object HRK
object IEP
object ILP
object ILR
object ISJ
object ITL
object LAJ
object LSM
object LTL
object LTT
object LUC
object LUF
object LUL
object LVL
object LVR
object MGF
object MLF
object MRO
object MTL
object MTP
object MVQ
object MWK_H
object MXP
object MZE
object MZM
object NIC
object NLG
object PEH
object PEI
object PEN_H
object PES
object PLZ
object PTE
object RHD
object ROK
object ROL
object RON_H
object RUR
object SDD
object SDG_H
object SDP
object SIT
object SKK
object SLL
object SRG
object STD
object SUR
object SZL_H
object TJR
object TMM
object TPE
object TRL
object TRY_H
object UAK
object UGS
object UGW
object USS
object UYN
object UYP
object VEB
object VEF
object VNC
object XEU
object XFO
object XFU
object XRE
object YDD
object YUD
object YUM
object YUN
object ZAL
object ZMK
object ZRN
object ZRZ
object ZWC
object ZWD
object ZWL
object ZWN
object ZWR
Show all

Provides the Default given instance and factory methods for CurrencyMathContext.

Provides the Default given instance and factory methods for CurrencyMathContext.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

A typeclass that defines the geographical usage of a currency, providing a mechanism to associate a currency with the set of Countries where it is officially used.

A typeclass that defines the geographical usage of a currency, providing a mechanism to associate a currency with the set of Countries where it is officially used.

Default given instances for all currencies known to the library are generated at build time and are automatically available when importing world.money.currency.*.

Type parameters

A

The specific currency singleton type, e.g., Currencies.KES.type.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
Show all
object CurrencyUsage

Provides methods for convenient access to usage territories of any currency record (e.g., Currency, HistoricCurrency) via the CurrencyUsage typeclass.

Provides methods for convenient access to usage territories of any currency record (e.g., Currency, HistoricCurrency) via the CurrencyUsage typeclass.

Attributes

Example
import world.money.currency.*
val shillingUsage: Set[Country] = Currencies.KES.usageTerritories
assert(shillingUsage.exists(_.alpha2.value == "KE"))
Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
object CurrencyValue

Provides factory methods and arithmetic operations for CurrencyValue.

Provides factory methods and arithmetic operations for CurrencyValue.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Represents a historic currency that is no longer in circulation.

Represents a historic currency that is no longer in circulation.

All historic currencies known to this library are available as predefined singleton objects within the HistoricCurrencies object.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
object ADP
object AFA
object ALK
object ANG
object AOK
object AON
object AOR
object ARA
object ARP
object ARY
object ATS
object AYM
object AZM
object BAD
object BEC
object BEF
object BEL
object BGJ
object BGK
object BGL
object BOP
object BRB
object BRC
object BRE
object BRN
object BRR
object BUK
object BYB
object BYR
object CHC
object CSD
object CSJ
object CSK
object CUC
object CYP
object DDM
object DEM
object ECS
object ECV
object EEK
object ESA
object ESB
object ESP
object FIM
object FRF
object GEK
object GHC
object GHP
object GNE
object GNS
object GQE
object GRD
object GWE
object GWP
object HRD
object HRK
object IEP
object ILP
object ILR
object ISJ
object ITL
object LAJ
object LSM
object LTL
object LTT
object LUC
object LUF
object LUL
object LVL
object LVR
object MGF
object MLF
object MRO
object MTL
object MTP
object MVQ
object MWK_H
object MXP
object MZE
object MZM
object NIC
object NLG
object PEH
object PEI
object PEN_H
object PES
object PLZ
object PTE
object RHD
object ROK
object ROL
object RON_H
object RUR
object SDD
object SDG_H
object SDP
object SIT
object SKK
object SLL
object SRG
object STD
object SUR
object SZL_H
object TJR
object TMM
object TPE
object TRL
object TRY_H
object UAK
object UGS
object UGW
object USS
object UYN
object UYP
object VEB
object VEF
object VNC
object XEU
object XFO
object XFU
object XRE
object YDD
object YUD
object YUM
object YUN
object ZAL
object ZMK
object ZRN
object ZRZ
object ZWC
object ZWD
object ZWL
object ZWN
object ZWR
Show all
object NumericCode

Provides factory methods for creating instances of NumericCode.

Provides factory methods for creating instances of NumericCode.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Types

opaque type CcyCode

A type-safe 3-letter uppercase ISO 4217 alphabetic currency code.

A type-safe 3-letter uppercase ISO 4217 alphabetic currency code.

This type ensures that any String representing a currency's alphabetic code conforms to the standard's format, preventing the use of arbitrary strings in monetary contexts.

Attributes

See also
Example
import world.money.currency.CcyCode
def printCode(code: CcyCode): Unit = println(s"Processing code: ${code.value}")
CcyCode.from("KES") match
case Right(kesCode) => printCode(kesCode)
case Left(error)    => println(error.getMessage)
opaque type CurrencyMathContext

A type-safe wrapper for java.math.MathContext for use in currency-related calculations; providing a way to manage precision and rounding behaviour when performing arithmetic on CurrencyValue instances. Using a distinct type prevents other MathContext instances from being accidentally used in monetary calculations.

A type-safe wrapper for java.math.MathContext for use in currency-related calculations; providing a way to manage precision and rounding behaviour when performing arithmetic on CurrencyValue instances. Using a distinct type prevents other MathContext instances from being accidentally used in monetary calculations.

A Default instance is provided.

Attributes

Example

You can override the default context for a specific scope by providing your own given instance.

import world.money.currency.{CurrencyValue, CurrencyMathContext}
import java.math.RoundingMode
// Define a custom context with lower precision and different rounding.
given lowPrecisionContext: CurrencyMathContext = CurrencyMathContext(4, RoundingMode.HALF_UP)
// All operations within this scope will now use `lowPrecisionContext`.
val result = CurrencyValue.divide(CurrencyValue(10), CurrencyValue(3)) // Right(3.333)
opaque type CurrencyValue

A type-safe representation of the numeric value of a monetary amount.

A type-safe representation of the numeric value of a monetary amount.

This type wraps BigDecimal to enforce that all arithmetic operations are performed using a controlled CurrencyMathContext, preventing common floating-point errors and ensuring consistent, calculations across the library.

Attributes

Example
import world.money.currency.CurrencyValue
def calculateTax(amount: CurrencyValue): CurrencyValue =
amount * CurrencyValue(0.16) // VAT at 16%
val price = CurrencyValue(2500)
val tax = calculateTax(price)
val total = price + tax // total is 2900
opaque type NumericCode

A type-safe 3-digit ISO 4217 numeric currency code.

A type-safe 3-digit ISO 4217 numeric currency code.

This type ensures that any Int representing a currency's numeric code falls within the standard's valid range.

Attributes

See also

Extensions

Extensions

extension (c: Currency)
transparent inline def apply(value: CurrencyValue | BigDecimal | Long | Int | Double): Money[c.type]

Creates a type-safe Money instance for this specific currency.

Creates a type-safe Money instance for this specific currency.

This factory method provides an ergonomic way to create Money values directly from a currency object. The resulting Money instance is strongly typed with this currency's specific singleton type.

Value parameters

value

The numeric amount for the new Money instance.

Attributes

Returns

A Money instance with its currency type fixed to this specific currency.

Note

Using Double can lead to floating-point precision inaccuracies. Prefer BigDecimal, String, Long, or Int.

Example
import world.money.currency.*
val oneHundredShillings: Money[Currencies.KES.type] = Currencies.KES(100)
val fiftyPounds: Money[Currencies.GBP.type] = Currencies.GBP(50.0)
extension [A <: CurrencyDetails](currency: A)
transparent inline def usage(using CurrencyUsage[A]): Set[Country]

Retrieves the set of countries where this specific currency is used.

Retrieves the set of countries where this specific currency is used.

This method relies on a given CurrencyUsage instance for this currency's specific type being available in the current scope.

Value parameters

usage

The implicitly provided CurrencyUsage instance.

Attributes

Returns

A Set of world.locale.country.Country instances.

Example
import world.money.currency.*
val countriesUsingKES = Currencies.KES.usage
extension (currency: CurrencyDetails)

Upcasts this currency instance to the general CurrencyDetails trait.

Upcasts this currency instance to the general CurrencyDetails trait.

This is a utility for situations, particularly in tests, where the compiler cannot equate a specific singleton type (e.g., Currencies.KES.type) with an existential one (? <: Currency). By upcasting both sides of a comparison to their common supertype, type-level comparison issues can be avoided.

Attributes

Returns

The same currency instance, but with its type widened to CurrencyDetails.

Example
import world.money.currency.*
val genericCurrency: CurrencyDetails = Currencies.KES.asCurrency

Exports

Defined exports