Skip to content

Commit

Permalink
Fix pattern matching with float
Browse files Browse the repository at this point in the history
  • Loading branch information
NickNeck committed Mar 17, 2024
1 parent 4346607 commit 669b8af
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/xema/validator.ex
Expand Up @@ -555,9 +555,10 @@ defmodule Xema.Validator do
defp multiple_of(%{multiple_of: multiple_of}, value) when is_number(value) do
x = value / multiple_of

case x - Float.floor(x) do
0.0 -> :ok
_ -> {:error, %{value: value, multiple_of: multiple_of}}
if x - Float.floor(x) == 0.0 do
:ok
else
{:error, %{value: value, multiple_of: multiple_of}}
end
end

Expand Down

0 comments on commit 669b8af

Please sign in to comment.