Money

Monetary calculations and allocations made easy:

val price = 100 money "USD"                     // USD 100.00
val shipping = 5 money "USD" // USD 5.00
val subtotal = price + shipping // USD 105.00
val discount = 10.percent() // 10%
val total = subtotal decreaseBy discount // USD 94.50

val ratios = listOf(60.percent(), 40.percent()) // [60%, 40%]

total allocate 2 // [USD 47.25, USD 47.25]
total allocate ratios // [USD 56.70, USD 37.80]

The library supports arithmetic operations with monetary amounts, calculations with percentages and allocation, making it simple to model use cases like installments payments (e.g., buy now, pay later), foreign exchange, investments yields, and tax collection. Cryptocurrencies are also fully supported out of the box:

val price = 0.01607580 money "BTC"           // BTC 0.01607580
val transactionFee = 1.25.percent() // 1.5%
val total = price increaseBy transactionFee // BTC 0.01627675
val installments = total allocate 3 // [BTC 0.00542559, BTC 0.00542558, BTC 0.00542558]

val rate = 62555.60 money "USD" // USD 62555.60
val totalInUsd = total exchange rate // USD 1005.63

Refer to the documentation for more about how to work with monetary amounts, supported currencies, available operations, rounding, and allocation.

Installation and documentation

The installation procedures and the documentation can be read in the project repository in GitHub.

Packages

Link copied to clipboard

Core functions and types.

Link copied to clipboard

Allocation features for Money.

Strategies for allocating the difference generated by the allocation operation.

Link copied to clipboard

Caching configuration.