scribe.decimal

Utils for the conversions and massaging of BigDecimal values.

->decimal-conformer

macro

(->decimal-conformer & {:keys [precision scale]})
Returns a `clojure.spec.alpha/conformer`, that conforms a `decimal?` with
`precision` and `scale`, returning `:clojure.spec.alpha/invalid` if
unsuccessful.

byte-buffer?

(byte-buffer? x)
Is `x` an instance of a `java.nio.ByteBuffer` or any of its subclasses?

bytes->decimal

(bytes->decimal buffer-or-bytes precision scale)
Converts a byte array or `ByteBuffer` containing the two's-complement
representation of an unscaled Integer value in big-endian byte
order to a `BigDecimal`.

decimal->bytes

(decimal->bytes bd precision scale)
Converts a `BigDecimal` `bd` to a `ByteBuffer` containing the
two's-complement representation of its underlying unscaled `BigInteger` value
in big-endian byte order.

decimal->fixed

(decimal->fixed bd precision scale)
Converts a `BigDecimal` to a `org.apache.avro.generic.GenericFixed`
containing the two's-complement representation of its underlying unscaled
BigInteger value in big-endian byte order.

TODO FIXME not implemented

fixed->decimal

(fixed->decimal fixed precision scale)
Converts an `org.apache.avro.generic.GenericFixed` containing the
two's-complement representation of an unscaled Integer value in big-endian
byte order to a `BigDecimal`.

TODO FIXME not really implemented

s-conform-decimal

(s-conform-decimal precision scale bd)
Conforms the `decimal?` `bd` with `precision` and `scale`, returning
`:clojure.spec.alpha/invalid` if unsuccessful.

This is the `f` in the call to `clojure.spec.alpha/conformer`.

NOTE you probably don't want to call this, use `->decimal-conformer` instead.

set-precision

(set-precision bd precision)
Sets the `precision` of a `BigDecimal` `bd`.

set-scale

(set-scale bd scale)
Sets the `scale` of a `BigDecimal` `bd`.