Compatibility layer for Decimal library operations.
Provides normalized function signatures for common Decimal
operations used throughout Localize.
Summary
Functions
Compares two Decimal values.
Arguments
decimal_1— aDecimal.t()value.decimal_2— aDecimal.t()value.
Returns
:ltifdecimal_1is less thandecimal_2.:eqif they are equal.:gtifdecimal_1is greater thandecimal_2.
Examples
iex> Localize.Utils.Decimal.compare(Decimal.new("1.0"), Decimal.new("2.0"))
:lt
Parses a string into a Decimal value.
Arguments
string— a string representation of a number.
Returns
{decimal, ""}if the string was successfully parsed.{:error, string}if the string could not be parsed.
Examples
iex> Localize.Utils.Decimal.parse("3.14")
{Decimal.new("3.14"), ""}
iex> Localize.Utils.Decimal.parse("not_a_number")
{:error, "not_a_number"}
Normalizes a Decimal value by removing trailing zeros from the coefficient.
Arguments
decimal— aDecimal.t()value to normalize.
Returns
- A normalized
Decimal.t().
Examples
iex> Localize.Utils.Decimal.reduce(Decimal.new("1.20"))
Decimal.new("1.2")