ericmj / decimal

Arbitrary precision decimal arithmetic

Home Page:https://hexdocs.pm/decimal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decimal.integer?/1 delivers false for 0.0 (and more 0)

corka149 opened this issue · comments

  • Decimal version: 2.0.0
  • Elixir version: Elixir 1.12.3 (compiled with Erlang/OTP 24)

Description

The function Decimal.integer?/1 returns false for 0.0. More zeroes can be append and the result remains false.
On the other hand Decimal.to_integer/1 is fine with converting the same decimal to an integer.

The documentation of Decimal.integer?/1 states:

Returns true when the given decimal has no significant digits after the decimal point.

From my point of view 0.0 matches this criteria.

What I Did

Here an example script:

Mix.install [{:decimal, "~> 2.0"}]

"0.0"
|> Decimal.new() 
|> Decimal.to_integer() 
|> IO.inspect(label: :as_integer)
# as_integer: 0

"0.0"
|> Decimal.new() 
|> Decimal.integer?() 
|> IO.inspect(label: :integer?)
# integer?: false

Is this a bug or did I interpret the documentation incorrectly? 😅