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]
type PrecisionOf[C <: Currency] = C match { case JPY.type => Some[0] case KRW.type => Some[0] case BHD.type => Some[3] case KWD.type => Some[3] case OMR.type => Some[3] case TND.type => Some[3] case Any => Option[Int] }
Match type that maps currency singleton types to their precision values.
Match type that maps currency singleton types to their precision values.
This type-level function encodes the number of decimal places (minor units) for each currency. It provides compile-time knowledge of precision for known currency types.
Common precision values:
0: Currencies like JPY (Japanese Yen), KRW (Korean Won)
2: Most currencies including KES, EUR, GBP
3: Currencies like OMR (Omani Riyal), KWD (Kuwaiti Dinar)
None: Precious metals and currencies without defined minor units
Type parameters
C
The currency singleton type (e.g., Currencies.KES.type)
Returns the precision (number of minor units) for a currency type.
Returns the precision (number of minor units) for a currency type.
This method provides compile-time constant folding when the currency type is statically known, while maintaining totality by falling back to runtime lookup for generic currency parameters.
Type parameters
C
The currency type whose precision is requested
Attributes
Returns
The number of decimal places for the currency, or None if not defined