Support for CLJC arbitrary precision decimal numerics. CLJ support for BigDecimal works well, but it is not directly supported in CLJS. Use the support in this ns when you need to write CLJC code that works the same in both.
You MUST include big.js as a js dependency for this to compile in CLJS.
Support for CLJC arbitrary precision decimal numerics. CLJ support for BigDecimal works well, but it is not directly supported in CLJS. Use the support in this ns when you need to write CLJC code that works the same in both. You MUST include big.js as a js dependency for this to compile in CLJS.
(*)
(* & numbers)
Multiply the given numbers, using bigdecimal math
Multiply the given numbers, using bigdecimal math
(+)
(+ & numbers)
Add the given numbers together, coercing any that are not numeric.
Add the given numbers together, coercing any that are not numeric.
(- & numbers)
Subtract the given numbers, using bigdecimal math
Subtract the given numbers, using bigdecimal math
(big->bigdec n)
Convert a low-level js Big number into a bigdecimal. No-op in CLJ.
WARNING: This is a low-level operation that should only be used if implementing your own extended functions for math.
Convert a low-level js Big number into a bigdecimal. No-op in CLJ. WARNING: This is a low-level operation that should only be used if implementing your own extended functions for math.
(div n d)
(div n d precision)
Divide the given two numbers, using bigdecimal math, with 20 digits
of precision. In primitive mode just uses regular /
.
Divide the given two numbers, using bigdecimal math, with 20 digits of precision. In primitive mode just uses regular `/`.
(floor n)
Returns the floor of n, which is n with all decimal digits removed.
Returns the floor of n, which is n with all decimal digits removed.
(n->big n)
Convert a number-like thing into a low-level js Big representation.
WARNING: This is a low-level operation that should only be used if implementing your own extended functions for math.
Convert a number-like thing into a low-level js Big representation. WARNING: This is a low-level operation that should only be used if implementing your own extended functions for math.
(negative n)
If n is positive then returns n*(-1) else returns n.
If n is positive then returns n*(-1) else returns n.
(negative? v)
Predicate for clj(s) negative bigdecimal
Predicate for clj(s) negative bigdecimal
(numeric s)
Coerce to a numeric from an arbitrary type (number, string, or numeric).
Coerce to a numeric from an arbitrary type (number, string, or numeric).
(numeric->currency-str n)
(numeric->currency-str n language country currency-code)
DEPRECATED: Use fulcro i18n support with something like js/Intl instead. js-joda locales are no longer the way to go, and this is not really a concern of numerics themselves.
Convert a numeric into a locale-specific currency string. The defaults are en
, US
, and USD
.
DEPRECATED: Use fulcro i18n support with something like js/Intl instead. js-joda locales are no longer the way to go, and this is not really a concern of numerics themselves. Convert a numeric into a locale-specific currency string. The defaults are `en`, `US`, and `USD`.
(numeric->percent-str n)
DEPRECATED: Use localization functions from i18n or js/Intl. This functions should never have been added here.
DEPRECATED: Use localization functions from i18n or js/Intl. This functions should never have been added here.
(numeric->str bd)
Convert a math number to a string.
Convert a math number to a string.
(numeric? v)
Predicate for clj(s) dynamic number (n or bigdecimal). Returns true if the given value is a numeric in the current computing context (primitive or BigDecimal).
Predicate for clj(s) dynamic number (n or bigdecimal). Returns true if the given value is a numeric in the current computing context (primitive or BigDecimal).
(positive n)
If n is negative then returns n*(-1) else returns n.
If n is negative then returns n*(-1) else returns n.
(positive? v)
Predicate for clj(s) positive bigdecimal
Predicate for clj(s) positive bigdecimal
(round n decimal-digits)
(round n decimal-digits rounding-mode)
Round the given number to the given number of decimal digits. Returns a new bigdecimal number. The rounding mode default to :half-up, but can also be :up, :down, or :half-even. You can change the default rounding mode via the dynamic var default-rounding-mode.
n can be nil (returns 0), a numeric string, a regular number, or a bigdecimal.
Round the given number to the given number of decimal digits. Returns a new bigdecimal number. The rounding mode default to :half-up, but can also be :up, :down, or :half-even. You can change the default rounding mode via the dynamic var *default-rounding-mode*. n can be nil (returns 0), a numeric string, a regular number, or a bigdecimal.
(with-primitive-ops & body)
Creates a thread-safe dynamic context where the math operations from this namespace use primitives instead of BigDecimal for speed.
Creates a thread-safe dynamic context where the math operations from this namespace use primitives instead of BigDecimal for speed.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close