Croma.SubtypeOfFloatWithConversionFromInt (croma v0.12.0)
View SourceHelper module to define float-based types.
The following members are generated by use Croma.SubtypeOfFloatWithConversionFromInt:
@type t@spec valid?(term) :: boolean@spec new(term) :: Croma.Result.t(t)
This variant of Croma.SubtypeOfFloat is useful for e.g. float field in a struct that
models JSON data so that both 1.0 and 1 in JSON representation can be automatically
converted to elixir's float value by new/1.
Options:
:min- Minimum value of this type (inclusive).:max- Maximum value of this type (inclusive).:default- Default value for this type. Passing this option generatesdefault/0.
Examples
defmodule MyFloat do
use Croma.SubtypeOfFloatWithConversionFromInt, min: 0.0, max: 5.0, default: 0.0
end