(->clojure-symbol a)
Converts an amount of the given money to a clojure symbol (with added M when needed).
Converts an amount of the given money to a clojure symbol (with added M when needed).
(->double a)
(->double a scale)
(->double a scale rounding-mode)
Converts an amount of the given money to double.
Converts an amount of the given money to double.
(->float a)
(->float a scale)
(->float a scale rounding-mode)
Converts an amount of the given money to float.
Converts an amount of the given money to float.
(->symbol a)
Converts an amount of the given money to a symbol.
Converts an amount of the given money to a symbol.
This protocol is used to express (monetary) values using various numeric types and currency representations.
This protocol is used to express (monetary) values using various numeric types and currency representations.
(cast money)
(cast money currency)
(cast money currency rounding-mode)
Casts an existing Money object to another having a different currency, rescaling
the amount and optionally rounding it. This is useful when operating on multiple
currency registries compatible with different data sources or processing
engines. For simply ensuring that a currency is sourced in the right registry, use
of-registry
.
Casts an existing Money object to another having a different currency, rescaling the amount and optionally rounding it. This is useful when operating on multiple currency registries compatible with different data sources or processing engines. For simply ensuring that a currency is sourced in the right registry, use `of-registry`.
(value num)
(value currency num)
(value currency num rounding-mode)
Creates new Money object for the given value which will become an amount. If the
currency is not given it will try to use the default one, taken from the
*default-currency*
dynamic variable. Optional rounding-mode should be a rounding
mode used when the conversion to a scaled monetary amount requires rounding.
In its unary form, when the argument is not numeric, it will try to get the currency object (identified by a string, a symbol or a keyword) from the default, global registry of currencies.
For simple money creation the following macros may be convenient way to go: of, of-major, of-minor.
Be careful about using number literals for big-scale amounts (16–17 digits). Use either big decimal literals, e.g. 1234.45689101112M, or strings.
Creates new Money object for the given value which will become an amount. If the currency is not given it will try to use the default one, taken from the `*default-currency*` dynamic variable. Optional rounding-mode should be a rounding mode used when the conversion to a scaled monetary amount requires rounding. In its unary form, when the argument is not numeric, it will try to get the currency object (identified by a string, a symbol or a keyword) from the default, global registry of currencies. For simple money creation the following macros may be convenient way to go: of, of-major, of-minor. Be careful about using number literals for big-scale amounts (16–17 digits). Use either big decimal literals, e.g. 1234.45689101112M, or strings.
(add)
(add a)
(add a b)
(add a b & more)
Adds two or more amounts of money of the same currency. When called without any arguments, returns 0.
Adds two or more amounts of money of the same currency. When called without any arguments, returns 0.
(add-major a b)
Increases major amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated.
Increases major amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated.
(add-minor a b)
Increases minor amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated..
Increases minor amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated..
(add-scaled)
(add-scaled a)
(add-scaled a b)
(add-scaled a b & more)
Alias for add.
Alias for add.
(amount money)
(amount a b)
(amount a b r)
Returns the amount of the given money.
Returns the amount of the given money.
(auto-scaled? m)
Returns true if the given Money object is based on a currency which is auto-scaled.
Returns true if the given Money object is based on a currency which is auto-scaled.
(compare a)
(compare a b)
Compares two monetary amounts of the same currency and scale. Returns -1 if the second one is less than, 0 if equal to, and 1 if it is greater than the first.
Compares two monetary amounts of the same currency and scale. Returns -1 if the second one is less than, 0 if equal to, and 1 if it is greater than the first.
(compare-amounts a)
(compare-amounts a b)
Compares two monetary amounts of the same currency, regardless of their scales. Returns -1 if the second one is less than, 0 if equal to, and 1 if it is greater than the first.
Compares two monetary amounts of the same currency, regardless of their scales. Returns -1 if the second one is less than, 0 if equal to, and 1 if it is greater than the first.
(convert money price)
(convert money price rounding-mode)
(convert money to-currency exchange-rate)
(convert money to-currency exchange-rate rounding-mode)
Converts a monetary amount from one currency to another using the given multiplier (expressing a conversion rate). When two money objects are given, the second one should express a price of 1 unit of the first currency.
When no rounding mode is given and rounding is required during scaling to another
currency then the value of dynamic variable
io.randomseed.bankster.scale/*rounding-mode*
will be used.
Converts a monetary amount from one currency to another using the given multiplier (expressing a conversion rate). When two money objects are given, the second one should express a price of 1 unit of the first currency. When no rounding mode is given and rounding is required during scaling to another currency then the value of dynamic variable `io.randomseed.bankster.scale/*rounding-mode*` will be used.
(currency money)
(currency a b)
(currency a b r)
Returns the currency of the given money.
Returns the currency of the given money.
(dec-major a)
Decreases major amount by 1.
Decreases major amount by 1.
(dec-minor a)
Decreases minor amount by 1.
Decreases minor amount by 1.
(defliteral c)
For the given currency identifier or a currency object it creates a tagged literal in a form of #money/CURRENCY where the CURRENCY is a currency code. As a side effect it creates a function of name io.randomseed.bankster.money/of-CURRENCY that will handle the literal.
The literals will be bound to data-readers in a local thread.
For the given currency identifier or a currency object it creates a tagged literal in a form of #money/CURRENCY where the CURRENCY is a currency code. As a side effect it creates a function of name io.randomseed.bankster.money/of-CURRENCY that will handle the literal. The literals will be bound to *data-readers* in a local thread.
(div a)
(div a b)
(div a b & more)
Divides two or more amounts of money of the same currency or numbers. If two of the given values are a kind of Money, the result will be a BigDecimal number. If the earlier value is a kind of Money and the second is a number, the result will be a Money. If the first argument is a number and the second argument is a monetary amount, an exception will be thrown. The result will always be either a kind of Money or a BigDecimal number.
For a single value it returns a division of 1 by the given number or monetary value.
For more than 2 arguments it repeatedly divides their values as described. If the previous calculations produce a regular number, all consequent divisors must be regular numbers. Practically, if the division begins with a monetary amount, only one monetary amount at some point later is permitted (which will cause the function to switch to the regular numbers calculation since the units will cancel themselves).
Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier.
For regular numbers and for monetary values of auto-scaled currencies the dynamic rescaling is performed to handle corner cases where there would be a non-terminating decimal expansion. Trailing zeros are stripped before any calculation.
Rescaling is performed after all calculations are done. However, the scale can be
applied on each calculation if the dynamic variable
io.randomseed.bankster.scale/*each*
is set to a truthy value. If the scaling
requires rounding then enclosing the expression within with-rounding
is
required. This can also be achieved by enclosing the expression within
io.randomseed.bankster.scale/with-rescaling
(aliased in this namespace under the
same name) macro combining the switch and setting the scale.
Divides two or more amounts of money of the same currency or numbers. If two of the given values are a kind of Money, the result will be a BigDecimal number. If the earlier value is a kind of Money and the second is a number, the result will be a Money. If the first argument is a number and the second argument is a monetary amount, an exception will be thrown. The result will always be either a kind of Money or a BigDecimal number. For a single value it returns a division of 1 by the given number or monetary value. For more than 2 arguments it repeatedly divides their values as described. If the previous calculations produce a regular number, all consequent divisors must be regular numbers. Practically, if the division begins with a monetary amount, only one monetary amount at some point later is permitted (which will cause the function to switch to the regular numbers calculation since the units will cancel themselves). Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier. For regular numbers and for monetary values of auto-scaled currencies the dynamic rescaling is performed to handle corner cases where there would be a non-terminating decimal expansion. Trailing zeros are stripped before any calculation. Rescaling is performed after all calculations are done. However, the scale can be applied on each calculation if the dynamic variable `io.randomseed.bankster.scale/*each*` is set to a truthy value. If the scaling requires rounding then enclosing the expression within `with-rounding` is required. This can also be achieved by enclosing the expression within `io.randomseed.bankster.scale/with-rescaling` (aliased in this namespace under the same name) macro combining the switch and setting the scale.
(div-rem a b)
Returns the remainder of dividing an mount of money by the given number.
Returns the remainder of dividing an mount of money by the given number.
(div-scaled a)
(div-scaled a b)
(div-scaled a b & more)
Divides two or more amounts of money of the same currency or numbers. Scales and optionally rounds each intermediate result (if there are more divisors).
If the first given argument is a kind of money and one of the divisors is also a kind of Money, the result will be a BigDecimal kind of number. If the earlier value is a kind of Money and the second is a number, the result will be a Money. If the first argument is a number and the second argument is a monetary amount, an exception will be thrown.
For a single value it returns a division of 1 by the given number or monetary value.
For more than 2 arguments it repeatedly divides their values as described and re-scales each result to match the scale of the first encountered monetary amount. If there are no monetary amounts involved the scale is calculated dynamically.
Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier.
For regular numbers and for monetary values of auto-scaled currencies the dynamic rescaling is performed to handle corner cases where there would be a non-terminating decimal expansion. Trailing zeros are stripped before any calculation.
If the scaling requires rounding then enclosing the expression within
with-rounding
(also present in io.randomseed.bankster.scale
namespace) is
required.
Divides two or more amounts of money of the same currency or numbers. Scales and optionally rounds each intermediate result (if there are more divisors). If the first given argument is a kind of money and one of the divisors is also a kind of Money, the result will be a BigDecimal kind of number. If the earlier value is a kind of Money and the second is a number, the result will be a Money. If the first argument is a number and the second argument is a monetary amount, an exception will be thrown. For a single value it returns a division of 1 by the given number or monetary value. For more than 2 arguments it repeatedly divides their values as described and re-scales each result to match the scale of the first encountered monetary amount. If there are no monetary amounts involved the scale is calculated dynamically. Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier. For regular numbers and for monetary values of auto-scaled currencies the dynamic rescaling is performed to handle corner cases where there would be a non-terminating decimal expansion. Trailing zeros are stripped before any calculation. If the scaling requires rounding then enclosing the expression within `with-rounding` (also present in `io.randomseed.bankster.scale` namespace) is required.
(eq-am? a)
(eq-am? a b)
(eq-am? a b & more)
Return true if the money amounts and their currencies are equal, regardless of their scales.
Return true if the money amounts and their currencies are equal, regardless of their scales.
(eq? a)
(eq? a b)
(eq? a b & more)
Return true if the money amounts and their currencies are equal. Note that currencies with different scales are considered different. Use eq-am? to compare amounts regardless of their scales.
Return true if the money amounts and their currencies are equal. Note that currencies with different scales are considered different. Use eq-am? to compare amounts regardless of their scales.
(format money)
(format money locale)
(format money locale opts)
Formats the given amount of money as a string according to localization rules. If the locale argument is not given then the default is used.
It is advised to express locale using a keyword when huge amount of operations is expected.
If there are 3 arguments passed the third one should be a map of options customizing the formatting. It can have the following keys:
scale/*rounding-mode*
is not set)The function assigned to the :currency-symbol-fn should take 3 arguments: currency, locale and registry.
Note that you may gain some speed by re-using the extended formatter (basic formatter is already cached). See the documentation of the format-with function for more information.
Formats the given amount of money as a string according to localization rules. If the locale argument is not given then the default is used. It is advised to express locale using a keyword when huge amount of operations is expected. If there are 3 arguments passed the third one should be a map of options customizing the formatting. It can have the following keys: - :rounding-mode - RoundingMode, rounding mode to apply when scaling (if `scale/*rounding-mode*` is not set) - :grouping - Boolean, if true then grouping will be used - :grouping-size - integer, size of a group when grouping - :negative-prefix - String, negative prefix to use - :negative-suffix - String, negative suffix to use - :positive-prefix - String, positive prefix to use - :positive-suffix - String, positive suffix to use - :always-sep-dec - Boolean, if true then the decimal separator will always be shown - :currency-symbol-fn - a function used on a bankster/Currency object to get its symbol as a string - :min-fraction-digits - integer, the minimum number of digits allowed in the fraction portion of an amount - :min-integer-digits - integer, the minimum number of digits allowed in the integer portion of an amount - :max-fraction-digits - integer, the maximum number of digits allowed in the fraction portion of an amount - :max-integer-digits - integer, the maximum number of digits allowed in the integer portion of an amount - :scale - sets both :min-fraction-digits and :max-fraction-digits to the same value. The function assigned to the :currency-symbol-fn should take 3 arguments: currency, locale and registry. Note that you may gain some speed by re-using the extended formatter (basic formatter is already cached). See the documentation of the format-with function for more information.
(format-with formatter money)
Formats the amount of money using the formatter provided. Formatters can be created with io.randomseed.bankster.currency/formatter and io.randomseed.bankster.currency/formatter-extended.
Formats the amount of money using the formatter provided. Formatters can be created with io.randomseed.bankster.currency/formatter and io.randomseed.bankster.currency/formatter-extended.
(ge? a)
(ge? a b)
(ge? a b & more)
Returns non-nil if monetary amounts are in monotonically non-increasing order, otherwise false.
Returns non-nil if monetary amounts are in monotonically non-increasing order, otherwise false.
(gt? a)
(gt? a b)
(gt? a b & more)
Returns non-nil if monetary amounts are in monotonically decreasing order, otherwise false.
Returns non-nil if monetary amounts are in monotonically decreasing order, otherwise false.
(inc-major a)
Increases major amount by 1.
Increases major amount by 1.
(inc-minor a)
Increases minor amount by 1.
Increases minor amount by 1.
(is-neg-or-zero? a)
Returns true if the given monetary amount is a negative number or zero.
Returns true if the given monetary amount is a negative number or zero.
(is-neg? a)
Returns true if the given monetary amount is a negative number.
Returns true if the given monetary amount is a negative number.
(is-pos-or-zero? a)
Returns true if the given monetary amount is a positive number or zero.
Returns true if the given monetary amount is a positive number or zero.
(is-pos? a)
Returns true if the given monetary amount is a positive number.
Returns true if the given monetary amount is a positive number.
(is-zero? a)
Returns true if the given monetary amount is a positive number.
Returns true if the given monetary amount is a positive number.
(le? a)
(le? a b)
(le? a b & more)
Returns non-nil if monetary amounts are in monotonically non-decreasing order, otherwise false.
Returns non-nil if monetary amounts are in monotonically non-decreasing order, otherwise false.
(lt? a)
(lt? a b)
(lt? a b & more)
Returns non-nil if monetary amounts are in monotonically increasing order, otherwise false.
Returns non-nil if monetary amounts are in monotonically increasing order, otherwise false.
(major a)
Returns the major part of the given amount of money.
Returns the major part of the given amount of money.
(major->int a)
Returns the major part of the given amount as a int number.
Returns the major part of the given amount as a int number.
(major->long a)
Returns the major part of the given amount as a long number.
Returns the major part of the given amount as a long number.
(major-minor a)
Returns a vector with major and minor parts of the given monetary amount.
Returns a vector with major and minor parts of the given monetary amount.
(major-minor->int a)
Returns a vector with major and minor parts of the given monetary amount represented as integer numbers.
Returns a vector with major and minor parts of the given monetary amount represented as integer numbers.
(major-minor->long a)
Returns a vector with major and minor parts of the given monetary amount represented as long numbers.
Returns a vector with major and minor parts of the given monetary amount represented as long numbers.
(major-value a)
(major-value currency amount)
(major-value currency amount rounding-mode)
Creates new Money object for the given value which will become a major part of the
amount. If the given number has fractional part it will be truncated. If the
currency is not given it should try to use the default one, taken from the
io.randomseed.bankster.currency/*default*
dynamic variable. Optional
rounding-mode should be a rounding mode used when the conversion to a scaled
monetary amount requires rounding.
For simple money creation the following macros may be convenient way to go: of, of-major, of-minor.
Creates new Money object for the given value which will become a major part of the amount. If the given number has fractional part it will be truncated. If the currency is not given it should try to use the default one, taken from the `io.randomseed.bankster.currency/*default*` dynamic variable. Optional rounding-mode should be a rounding mode used when the conversion to a scaled monetary amount requires rounding. For simple money creation the following macros may be convenient way to go: of, of-major, of-minor.
(max-amount a)
(max-amount a b)
(max-amount a b & more)
Returns the greatest of the monetary amounts.
Returns the greatest of the monetary amounts.
(min-amount a)
(min-amount a b)
(min-amount a b & more)
Returns the least of the monetary amounts.
Returns the least of the monetary amounts.
(minor a)
Returns the minor part of the given amount.
Returns the minor part of the given amount.
(minor->int a)
Returns the minor part of the given amount as an integer number.
Returns the minor part of the given amount as an integer number.
(minor->long a)
Returns the minor part of the given amount as a long number.
Returns the minor part of the given amount as a long number.
(minor-value a)
(minor-value currency amount)
(minor-value currency amount rounding-mode)
Creates new Money object for the given value which will become a minor part of the
amount. If the given number has fractional part it will be truncated. If the
currency is not given it should try to use the default one, taken from the
io.randomseed.bankster.currency/*default*
dynamic variable. Optional
rounding-mode should be a rounding mode used when the conversion to a scaled
monetary amount requires rounding.
For simple money creation the following macros may be convenient way to go: of, of-major, of-minor.
Creates new Money object for the given value which will become a minor part of the amount. If the given number has fractional part it will be truncated. If the currency is not given it should try to use the default one, taken from the `io.randomseed.bankster.currency/*default*` dynamic variable. Optional rounding-mode should be a rounding mode used when the conversion to a scaled monetary amount requires rounding. For simple money creation the following macros may be convenient way to go: of, of-major, of-minor.
(money? a)
Returns true if the given value is a kind of Money.
Returns true if the given value is a kind of Money.
(mul)
(mul a)
(mul a b)
(mul a b & more)
Multiplies two or more values where one may be a Money object. If one of the values is a kind of Money then the result will also be a kind of Money. For a single value it simply returns it. For more than 2 arguments it repeatedly multiplies them as described.
When there is a multiplication of a monetary value by the regular number, the final
result of all operations is re-scaled to match the scale of monetary amount. If the
scaling requires rounding, enclosing the expression within
io.randomseed.bankster.scale/with-rounding
is required (the macro is aliased
under the same name in this namespace).
Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier.
For regular numbers dynamic rescaling is performed only to handle corner cases where there would be a non-terminating decimal expansion.
Rescaling is performed after performing all operations unless all values are regular numbers (without any Money object among them).
Multiplies two or more values where one may be a Money object. If one of the values is a kind of Money then the result will also be a kind of Money. For a single value it simply returns it. For more than 2 arguments it repeatedly multiplies them as described. When there is a multiplication of a monetary value by the regular number, the final result of all operations is re-scaled to match the scale of monetary amount. If the scaling requires rounding, enclosing the expression within `io.randomseed.bankster.scale/with-rounding` is required (the macro is aliased under the same name in this namespace). Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier. For regular numbers dynamic rescaling is performed only to handle corner cases where there would be a non-terminating decimal expansion. Rescaling is performed after performing all operations unless all values are regular numbers (without any Money object among them).
(mul-scaled)
(mul-scaled a)
(mul-scaled a b)
(mul-scaled a b & more)
Multiplies two or more values where one may be a Money object. If one of the values is a kind of Money then the result will also be a kind of Money. For a single value it simply returns it. For more than 2 arguments it repeatedly multiplies them as described.
When there is a multiplication of a monetary value by the regular number, the final
result of all operations is re-scaled to match the scale of the monetary amount. If
the scaling requires rounding, enclosing the expression within
io.randomseed.bankster.scale/with-rounding
is required (the macro is aliased
under the same name in this namespace).
Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier.
For regular numbers dynamic rescaling is performed only to handle corner cases where there would be a non-terminating decimal expansion.
Rescaling is performed on each operation unless/until all values are regular numbers (without any Money object among them).
Multiplies two or more values where one may be a Money object. If one of the values is a kind of Money then the result will also be a kind of Money. For a single value it simply returns it. For more than 2 arguments it repeatedly multiplies them as described. When there is a multiplication of a monetary value by the regular number, the final result of all operations is re-scaled to match the scale of the monetary amount. If the scaling requires rounding, enclosing the expression within `io.randomseed.bankster.scale/with-rounding` is required (the macro is aliased under the same name in this namespace). Note that rescaling is not based on the original scale of a currency. This is designed that way is to handle cases when monetary amount was intentionally rescaled earlier. For regular numbers dynamic rescaling is performed only to handle corner cases where there would be a non-terminating decimal expansion. Rescaling is performed on each operation unless/until all values are regular numbers (without any Money object among them).
(ne-am? a)
(ne-am? a b)
(ne-am? a b & more)
Returns true if the money amounts or their currencies are different, regardless of their scales.
Returns true if the money amounts or their currencies are different, regardless of their scales.
(ne? a)
(ne? a b)
(ne? a b & more)
Returns true if the money amounts or their currencies are different, regardless of their scales. Note that currencies with different scales are considered different.
Returns true if the money amounts or their currencies are different, regardless of their scales. Note that currencies with different scales are considered different.
(neg a)
Returns the negated amount of the given money. For negative amount it will reverse their sign. Same as (sub x).
Returns the negated amount of the given money. For negative amount it will reverse their sign. Same as (sub x).
(of)
(of a)
(of a b)
(of a b rounding-mode)
Returns the amount of money as a Money object consisting of a currency and a value. Currency can be a currency object and for registered currencies: a keyword, a symbol or a string (e.g. EUR, :EUR, "PLN" or crypto/ETH), or even a number (for ISO-compliant currencies).
The given amount can be any numeric value or a string that can be converted to java.math.BigDecimal.
When a number must be downscaled to fulfill the number of decimal places for a currency, rounding mode must be given, which may be a symbol, a keyword or a string of the following:
To create a monetary object using function, call io.randomseed.bankster.money/value
.
Be careful about using number literals for big-scale amounts (16–17 digits). Use either big decimal literals, e.g. 1234.45689101112M, or strings.
Returns the amount of money as a Money object consisting of a currency and a value. Currency can be a currency object and for registered currencies: a keyword, a symbol or a string (e.g. EUR, :EUR, "PLN" or crypto/ETH), or even a number (for ISO-compliant currencies). The given amount can be any numeric value or a string that can be converted to java.math.BigDecimal. When a number must be downscaled to fulfill the number of decimal places for a currency, rounding mode must be given, which may be a symbol, a keyword or a string of the following: * CEILING - rounds towards positive infinity. * DOWN - rounds towards zero. * FLOOR - rounds towards negative infinity. * HALF_DOWN - rounds towards nearest neighbor unless both neighbors are equidistant, in which case rounds down. * HALF_EVEN - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds towards the even. * HALF_UP - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds up. * UP – rounds away from zero * UNNECESSARY - asserts that the requested operation has an exact result, hence no rounding is necessary. To create a monetary object using function, call `io.randomseed.bankster.money/value`. Be careful about using number literals for big-scale amounts (16–17 digits). Use either big decimal literals, e.g. 1234.45689101112M, or strings.
(of-major)
(of-major a)
(of-major a b)
(of-major a b rounding-mode)
Like io.randomseed.money/of but sets the amount of major part only.
Like io.randomseed.money/of but sets the amount of major part only.
(of-minor)
(of-minor a)
(of-minor a b)
(of-minor a b rounding-mode)
Like io.randomseed.money/of but sets the amount of minor part only.
Like io.randomseed.money/of but sets the amount of minor part only.
(of-registry money)
(of-registry registry money)
(of-registry registry money rounding-mode)
Ensures that a currency of the given money originates from the given registry. If the registry is not given and a dynamic registry is not set, the default one is used. Optional rounding-mode can be supplied to be used when downscaling is needed (nominal currency from a registry has lower number of decimal places than the amount of money).
Money can be expressed as a Money object or any other object that will create Money
when passed to the value
function. Returns money.
Ensures that a currency of the given money originates from the given registry. If the registry is not given and a dynamic registry is not set, the default one is used. Optional rounding-mode can be supplied to be used when downscaling is needed (nominal currency from a registry has lower number of decimal places than the amount of money). Money can be expressed as a Money object or any other object that will create Money when passed to the `value` function. Returns money.
(on-amount money f)
(on-amount money f a)
(on-amount money f a b)
(on-amount money f a b & more)
Performs an operation expressed with a function f on an amount of the given money. Additional arguments will be passed to the f. Returns the money with the amount updated. The function f must return a number. Short-circuits on nil as an argument.
Performs an operation expressed with a function f on an amount of the given money. Additional arguments will be passed to the f. Returns the money with the amount updated. The function f must return a number. Short-circuits on nil as an argument.
(pos a)
Returns the positive (absolute) amount of the given money.
Returns the positive (absolute) amount of the given money.
(rescale money)
(rescale money scale)
(rescale money scale rounding-mode)
Same as scale but its unary variant it will rescale an amount of the given money to
conform it to its currency settings instead of returning the scale. It has the same
effect as calling io.randomseed.bankster.scale/apply
on a money object without
passing any other arguments.
Same as scale but its unary variant it will rescale an amount of the given money to conform it to its currency settings instead of returning the scale. It has the same effect as calling `io.randomseed.bankster.scale/apply` on a money object without passing any other arguments.
(rescaled? a)
Returns true if the given monetary value has different scale than its currency (so it was rescaled). Returns false if the scale is no different. Returns nil if the currency does not have a fixed scale.
Returns true if the given monetary value has different scale than its currency (so it was rescaled). Returns false if the scale is no different. Returns nil if the currency does not have a fixed scale.
(round money scale)
(round money scale rounding-mode)
Rounds the amount of money using the given scale and rounding mode. Returns money with rounded amount preserving the original scale. If the rounding mode is not given the one from scale/rounding-mode is used.
Rounds the amount of money using the given scale and rounding mode. Returns money with rounded amount preserving the original scale. If the rounding mode is not given the one from scale/*rounding-mode* is used.
(same-currencies? a b)
Returns true if both currencies are the same for the given money objects.
Returns true if both currencies are the same for the given money objects.
(same-currency-ids? a b)
Returns true if both currencies have the same IDs for the given money objects.
Returns true if both currencies have the same IDs for the given money objects.
(scale money)
(scale money scale)
(scale money scale rounding-mode)
Re-scales the given money using a scale (number of decimal places) and an optional rounding mode (required when downscaling). The internal scale for a currency object is NOT updated. If no scale is given, returns the current scale of an amount (not the nominal scale of a currency – which is important in rescaled amount or auto-scaled currencies).
Auto-scaled monetary values are returned unchanged.
Use with caution since it can make money object no longer compliant with a scale of the currency.
Re-scales the given money using a scale (number of decimal places) and an optional rounding mode (required when downscaling). The internal scale for a currency object is NOT updated. If no scale is given, returns the current scale of an amount (not the nominal scale of a currency – which is important in rescaled amount or auto-scaled currencies). Auto-scaled monetary values are returned unchanged. Use with caution since it can make money object no longer compliant with a scale of the currency.
(strip a)
Strips trailing zeros from the amount of money. The internal scale for a currency object is NOT updated.
Use with caution since it can make money object no longer compliant with a scale of the registered currency.
Strips trailing zeros from the amount of money. The internal scale for a currency object is NOT updated. Use with caution since it can make money object no longer compliant with a scale of the registered currency.
(stripped-amount money)
(stripped-amount a b)
(stripped-amount a b r)
Returns the amount of the given money with trailing zeros removed.
Returns the amount of the given money with trailing zeros removed.
(sub a)
(sub a b)
(sub a b & more)
Subtracts two or more amounts of money of the same currency. When called with a single argument, negates its value.
Subtracts two or more amounts of money of the same currency. When called with a single argument, negates its value.
(sub-major a b)
Decreases major amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated.
Decreases major amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated.
(sub-minor a b)
Decreases minor amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated. If the major component comes from a money object, its currency must match the given money. This check is performed to prevent mistakes; if you need to subtract minor parts of money with different currencies, use (minor x) on the second argument.
Decreases minor amount by the given number. If the number is also expressed as money and it has decimal parts, they will be truncated. If the major component comes from a money object, its currency must match the given money. This check is performed to prevent mistakes; if you need to subtract minor parts of money with different currencies, use (minor x) on the second argument.
(sub-scaled a)
(sub-scaled a b)
(sub-scaled a b & more)
Alias for sub.
Alias for sub.
(unparse money)
(unparse a b)
(unparse a b r)
Returns a vector with symbolic representations of amount and currency. Useful for printing to EDN or displaying on a console. The letter M will be added to the amount if its precision exceeds 15.
Returns a vector with symbolic representations of amount and currency. Useful for printing to EDN or displaying on a console. The letter M will be added to the amount if its precision exceeds 15.
(with-currency currency & body)
Sets a default currency in a lexical context of the body. Has the same effect as io.randomseed.bankster.currency/with.
Sets a default currency in a lexical context of the body. Has the same effect as io.randomseed.bankster.currency/with.
(with-rescaling rounding-mode & body)
Alias for io.randomseed.bankster.scale/with-rescaling.
Alias for io.randomseed.bankster.scale/with-rescaling.
(with-rounding rounding-mode & body)
Alias for io.randomseed.bankster.scale/with-rounding.
Alias for io.randomseed.bankster.scale/with-rounding.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close