defmodule ExShopifySchema.Graphql.Float do @moduledoc "Represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point)." @type t() :: float() use Ecto.Type @impl Ecto.Type def type, do: :float @impl Ecto.Type def cast(nil), do: {:ok, nil} # NOTE: Numbers in JSON can be an integer or a floating point. def cast(int) when is_integer(int), do: {:ok, int / 1} def cast(float) when is_float(float), do: {:ok, float} def cast(_data), do: :error @impl Ecto.Type def load(data), do: cast(data) @impl Ecto.Type def dump(nil), do: {:ok, nil} def dump(float) when is_float(float), do: {:ok, float} def dump(_data), do: :error end