Packages

Exchema is a library to define data types and validate it

Current section

Files

Jump to
exchema lib exchema coercions float.ex
Raw

lib/exchema/coercions/float.ex

defmodule Exchema.Coercions.Float do
@moduledoc false
def coerce(integer) when is_integer(integer), do: integer * 1.0
def coerce(str) when is_binary(str) do
case Float.parse(str) do
{new, _} -> new
:error -> str
end
end
def coerce(v), do: v
end