Math utilities for Rujira financial calculations
Summary
Functions
Average of two numbers
Divide two numbers and round down to integer
Round down to integer using floor
Multiply two numbers and round down to integer
Convert number from one decimal precision to another
Safe division that returns 0 if divisor is zero
Parses any value to a Decimal. nil passes through.
Parses any value to an integer. nil passes through.
Functions
Average of two numbers
Divide two numbers and round down to integer
Round down to integer using floor
Multiply two numbers and round down to integer
Convert number from one decimal precision to another
Safe division that returns 0 if divisor is zero
@spec to_decimal(nil | integer() | float() | String.t() | Decimal.t()) :: {:ok, Decimal.t() | nil} | {:error, :invalid_decimal}
Parses any value to a Decimal. nil passes through.
Returns {:ok, Decimal.t}, {:ok, nil}, or {:error, :invalid_decimal}.
@spec to_integer(nil | integer() | String.t()) :: {:ok, integer() | nil} | {:error, :invalid_integer}
Parses any value to an integer. nil passes through.
Returns {:ok, integer}, {:ok, nil}, or {:error, :invalid_integer}.