Packages
cldr_utils
2.13.0
2.29.7
2.29.6
2.29.5
2.29.4
2.29.3
2.29.2
2.29.1
2.29.0
2.28.3
2.28.2
2.28.1
2.28.0
2.27.0
2.26.0
2.25.0
2.24.2
2.24.1
2.24.0
2.23.1
2.23.0
2.22.0
2.21.0
2.20.0
2.19.2
2.19.1
2.19.0
2.18.0
2.17.2
2.17.1
2.17.0
2.17.0-rc.0
2.16.0
2.15.1
2.15.0
2.14.1
2.14.0
2.13.3
retired
2.13.2
2.13.1
2.13.0
retired
2.12.0
2.11.0
2.10.0
2.9.1
2.9.0
retired
2.8.0
2.7.0
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
Map, Calendar, Digits, Decimal, HTTP, Macro, Math, and String helpers for ex_cldr.
Retired package: Deprecated - deprecated
Current section
Files
Jump to
Current section
Files
lib/cldr/utils/decimal.ex
defmodule Cldr.Decimal do
@moduledoc """
Adds a compatibility layer for functions which changed
either semantics or returns types between Decimal version
1.x and 2.x
"""
Code.ensure_loaded(Decimal)
decimal_version = (Application.spec(:decimal, :vsn) || '1.9.0') |> List.to_string
# To cater for both Decimal 1.x and 2.x
if Code.ensure_loaded?(Decimal) && function_exported?(Decimal, :normalize, 1) do
def reduce(decimal) do
Decimal.normalize(decimal)
end
else
def reduce(decimal) do
Decimal.reduce(decimal)
end
end
def compare(decimal1, decimal2) do
Cldr.Math.decimal_compare(decimal1, decimal2)
end
if Version.match?(decimal_version, "~> 2.0") do
def parse(string) do
case Decimal.parse(string) do
{decimal, ""} -> {decimal, ""}
_other -> {:error, string}
end
end
else
def parse(string) do
case Decimal.parse(string) do
{:ok, decimal} -> {decimal, ""}
_other -> {:error, string}
end
end
end
end