DarkMatter.Decimals.Conversion (DarkMatter v1.1.4) View Source

Decimal conversion functions

Link to this section Summary

Functions

((n + (factor/2)) / factor) * factor

Determine if a number is rounded.

Generic to integer function

Transform a t:stringable.t/0 into a normalized string.

Transform a t:stringable.t/0 into a normalized formatted string.

Link to this section Types

Specs

conversion_modes() :: :normal | :reduced

Specs

round_option() :: {:round_up, pos_integer()}

Specs

round_options() :: [round_option(), ...]

Specs

stringable() :: String.t() | nil | Decimal.t()

Specs

to_string_formatter() :: :usd

Link to this section Functions

Link to this function

cast_decimal(decimal, mode \\ :reduced)

View Source

Specs

cast_decimal(any(), conversion_modes()) :: :error | nil | Decimal.t()

Cast Decimal

Link to this function

cast_decimal!(numeric, mode \\ :reduced)

View Source

Specs

cast_decimal!(any(), conversion_modes()) :: Decimal.t()

Cast Decimal

Link to this function

cast_decimal_ok(numeric, mode \\ :reduced)

View Source

Specs

cast_decimal_ok(any(), conversion_modes()) :: {:ok, Decimal.t()} | :error

Cast Decimal ok

Link to this function

decimal_round_ok(amount, list)

View Source

Specs

decimal_round_ok(any(), round_options()) :: {:ok, Decimal.t()} | :error

((n + (factor/2)) / factor) * factor

Specs

rounded?(any(), round_options()) :: boolean()

Determine if a number is rounded.

Specs

Generic to integer function

Specs

to_string(stringable()) :: String.t() | nil

Transform a t:stringable.t/0 into a normalized string.

Raises ArgumentError if a given binary isn't a valid Decimal.

Link to this function

to_string(stringable, atom)

View Source

Specs

to_string(stringable(), to_string_formatter()) :: String.t() | nil

Transform a t:stringable.t/0 into a normalized formatted string.

Raises ArgumentError if a given binary isn't a valid Decimal.