diff --git a/validate.go b/validate.go index b25919c3..b9b09ae1 100644 --- a/validate.go +++ b/validate.go @@ -493,7 +493,7 @@ func Validate(r Registry, s *Schema, path *PathBuffer, mode ValidateMode, v any, } } if s.MultipleOf != nil { - if math.Mod(num, *s.MultipleOf) != 0 { + if r := math.Mod(num, *s.MultipleOf); math.Abs(r) > 1e-9 && math.Abs(r-*s.MultipleOf) > 1e-9 { res.Add(path, v, s.msgMultipleOf) } } diff --git a/validate_test.go b/validate_test.go index a1ec5803..38723eb9 100644 --- a/validate_test.go +++ b/validate_test.go @@ -212,6 +212,13 @@ var validateTests = []struct { input: map[string]any{"value": 2}, errs: []string{"expected number to be a multiple of 5"}, }, + { + name: "multiple of float success", + typ: reflect.TypeFor[struct { + Value float64 "json:\"value\" multipleOf:\"0.01\"" + }](), + input: map[string]any{"value": 0.36}, + }, { name: "string success", typ: reflect.TypeFor[string](),