world.money.currency
Members list
Type members
Classlikes
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Currencies.type
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 CurrencyDetailstrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
- Known subtypes
-
object AEDobject AFNobject ALLobject AMDobject AOAobject ARSobject AUDobject AWGobject AZNobject BAMobject BBDobject BDTobject BGNobject BHDobject BIFobject BMDobject BNDobject BOBobject BOVobject BRLobject BSDobject BTNobject BWPobject BYNobject BZDobject CADobject CDFobject CHEobject CHFobject CHWobject CLFobject CLPobject CNYobject COPobject COUobject CRCobject CUPobject CVEobject CZKobject DJFobject DKKobject DOPobject DZDobject EGPobject ERNobject ETBobject EURobject FJDobject FKPobject GBPobject GELobject GHSobject GIPobject GMDobject GNFobject GTQobject GYDobject HKDobject HNLobject HTGobject HUFobject IDRobject ILSobject INRobject IQDobject IRRobject ISKobject JMDobject JODobject JPYobject KESobject KGSobject KHRobject KMFobject KPWobject KRWobject KWDobject KYDobject KZTobject LAKobject LBPobject LKRobject LRDobject LSLobject LYDobject MADobject MDLobject MGAobject MKDobject MMKobject MNTobject MOPobject MRUobject MURobject MVRobject MWKobject MXNobject MXVobject MYRobject MZNobject NADobject NGNobject NIOobject NOKobject NPRobject NZDobject OMRobject PABobject PENobject PGKobject PHPobject PKRobject PLNobject PYGobject QARobject RONobject RSDobject RUBobject RWFobject SARobject SBDobject SCRobject SDGobject SEKobject SGDobject SHPobject SLEobject SOSobject SRDobject SSPobject STNobject SVCobject SYPobject SZLobject THBobject TJSobject TMTobject TNDobject TOPobject TRYobject TTDobject TWDobject TZSobject UAHobject UGXobject USDobject USNobject UYIobject UYUobject UYWobject UZSobject VEDobject VESobject VNDobject VUVobject WSTobject XAFobject XAGobject XAUobject XBAobject XBBobject XBCobject XBDobject XCDobject XCGobject XDRobject XOFobject XPDobject XPFobject XPTobject XSUobject XTSobject XUAobject XXXobject YERobject ZARobject ZMWobject ZWGShow all
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 Objecttrait Matchableclass Any
- Self type
-
Currency.type
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 Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
- Known subtypes
-
trait Currencyobject AEDobject AFNobject ALLobject AMDobject AOAobject ARSobject AUDobject AWGobject AZNobject BAMobject BBDobject BDTobject BGNobject BHDobject BIFobject BMDobject BNDobject BOBobject BOVobject BRLobject BSDobject BTNobject BWPobject BYNobject BZDobject CADobject CDFobject CHEobject CHFobject CHWobject CLFobject CLPobject CNYobject COPobject COUobject CRCobject CUPobject CVEobject CZKobject DJFobject DKKobject DOPobject DZDobject EGPobject ERNobject ETBobject EURobject FJDobject FKPobject GBPobject GELobject GHSobject GIPobject GMDobject GNFobject GTQobject GYDobject HKDobject HNLobject HTGobject HUFobject IDRobject ILSobject INRobject IQDobject IRRobject ISKobject JMDobject JODobject JPYobject KESobject KGSobject KHRobject KMFobject KPWobject KRWobject KWDobject KYDobject KZTobject LAKobject LBPobject LKRobject LRDobject LSLobject LYDobject MADobject MDLobject MGAobject MKDobject MMKobject MNTobject MOPobject MRUobject MURobject MVRobject MWKobject MXNobject MXVobject MYRobject MZNobject NADobject NGNobject NIOobject NOKobject NPRobject NZDobject OMRobject PABobject PENobject PGKobject PHPobject PKRobject PLNobject PYGobject QARobject RONobject RSDobject RUBobject RWFobject SARobject SBDobject SCRobject SDGobject SEKobject SGDobject SHPobject SLEobject SOSobject SRDobject SSPobject STNobject SVCobject SYPobject SZLobject THBobject TJSobject TMTobject TNDobject TOPobject TRYobject TTDobject TWDobject TZSobject UAHobject UGXobject USDobject USNobject UYIobject UYUobject UYWobject UZSobject VEDobject VESobject VNDobject VUVobject WSTobject XAFobject XAGobject XAUobject XBAobject XBBobject XBCobject XBDobject XCDobject XCGobject XDRobject XOFobject XPDobject XPFobject XPTobject XSUobject XTSobject XUAobject XXXobject YERobject ZARobject ZMWobject ZWGtrait HistoricCurrencyobject ADPobject AFAobject ALKobject ANGobject AOKobject AONobject AORobject ARAobject ARPobject ARYobject ATSobject AYMobject AZMobject BADobject BECobject BEFobject BELobject BGJobject BGKobject BGLobject BOPobject BRBobject BRCobject BREobject BRNobject BRRobject BUKobject BYBobject BYRobject CHCobject CSDobject CSJobject CSKobject CUCobject CYPobject DDMobject DEMobject ECSobject ECVobject EEKobject ESAobject ESBobject ESPobject FIMobject FRFobject GEKobject GHCobject GHPobject GNEobject GNSobject GQEobject GRDobject GWEobject GWPobject HRDobject HRKobject IEPobject ILPobject ILRobject ISJobject ITLobject LAJobject LSMobject LTLobject LTTobject LUCobject LUFobject LULobject LVLobject LVRobject MGFobject MLFobject MROobject MTLobject MTPobject MVQobject MWK_Hobject MXPobject MZEobject MZMobject NICobject NLGobject PEHobject PEIobject PEN_Hobject PESobject PLZobject PTEobject RHDobject ROKobject ROLobject RON_Hobject RURobject SDDobject SDG_Hobject SDPobject SITobject SKKobject SLLobject SRGobject STDobject SURobject SZL_Hobject TJRobject TMMobject TPEobject TRLobject TRY_Hobject UAKobject UGSobject UGWobject USSobject UYNobject UYPobject VEBobject VEFobject VNCobject XEUobject XFOobject XFUobject XREobject YDDobject YUDobject YUMobject YUNobject ZALobject ZMKobject ZRNobject ZRZobject ZWCobject ZWDobject ZWLobject ZWNobject ZWRShow all
Provides the Default given instance and factory methods for CurrencyMathContext.
Provides the Default given instance and factory methods for CurrencyMathContext.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
CurrencyMathContext.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 Objecttrait Matchableclass Any
- Known subtypes
-
Show all
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 Objecttrait Matchableclass Any
- Self type
-
CurrencyUsage.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Provides factory methods and arithmetic operations for CurrencyValue.
Provides factory methods and arithmetic operations for CurrencyValue.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
CurrencyValue.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
HistoricCurrencies.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 CurrencyDetailstrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
- Known subtypes
-
object ADPobject AFAobject ALKobject ANGobject AOKobject AONobject AORobject ARAobject ARPobject ARYobject ATSobject AYMobject AZMobject BADobject BECobject BEFobject BELobject BGJobject BGKobject BGLobject BOPobject BRBobject BRCobject BREobject BRNobject BRRobject BUKobject BYBobject BYRobject CHCobject CSDobject CSJobject CSKobject CUCobject CYPobject DDMobject DEMobject ECSobject ECVobject EEKobject ESAobject ESBobject ESPobject FIMobject FRFobject GEKobject GHCobject GHPobject GNEobject GNSobject GQEobject GRDobject GWEobject GWPobject HRDobject HRKobject IEPobject ILPobject ILRobject ISJobject ITLobject LAJobject LSMobject LTLobject LTTobject LUCobject LUFobject LULobject LVLobject LVRobject MGFobject MLFobject MROobject MTLobject MTPobject MVQobject MWK_Hobject MXPobject MZEobject MZMobject NICobject NLGobject PEHobject PEIobject PEN_Hobject PESobject PLZobject PTEobject RHDobject ROKobject ROLobject RON_Hobject RURobject SDDobject SDG_Hobject SDPobject SITobject SKKobject SLLobject SRGobject STDobject SURobject SZL_Hobject TJRobject TMMobject TPEobject TRLobject TRY_Hobject UAKobject UGSobject UGWobject USSobject UYNobject UYPobject VEBobject VEFobject VNCobject XEUobject XFOobject XFUobject XREobject YDDobject YUDobject YUMobject YUNobject ZALobject ZMKobject ZRNobject ZRZobject ZWCobject ZWDobject ZWLobject ZWNobject ZWRShow all
Provides factory methods for creating instances of NumericCode.
Provides factory methods for creating instances of NumericCode.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
NumericCode.type
Types
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)
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
giveninstance.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)
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
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
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
Moneyinstance.
Attributes
- Returns
-
A
Moneyinstance with its currency type fixed to this specific currency. - Note
-
Using
Doublecan lead to floating-point precision inaccuracies. PreferBigDecimal,String,Long, orInt. - Example
-
import world.money.currency.* val oneHundredShillings: Money[Currencies.KES.type] = Currencies.KES(100) val fiftyPounds: Money[Currencies.GBP.type] = Currencies.GBP(50.0)
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
Setof world.locale.country.Country instances. - Example
-
import world.money.currency.* val countriesUsingKES = Currencies.KES.usage
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