Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"A": "gt=0.1,lt=0.9" there is a bad case in lt #1144

Closed
2 tasks done
ahaooahaz opened this issue Aug 16, 2023 · 1 comment · Fixed by #1146
Closed
2 tasks done

"A": "gt=0.1,lt=0.9" there is a bad case in lt #1144

ahaooahaz opened this issue Aug 16, 2023 · 1 comment · Fixed by #1146

Comments

@ahaooahaz
Copy link

ahaooahaz commented Aug 16, 2023

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10: v10

Issue, Question or Enhancement: Issue

I found there is an bad case with lt=float

Code sample, to showcase or reproduce:

package main

import (
	"fmt"

	"github.com/go-playground/validator/v10"
)

type Data struct {
	A float32
}

var validate = validator.New()

func main() {
	data1 := Data{
		A: 0.9,
	}

        data1 := Data{
		A: 0.1,
	}

	rules := map[string]string{
		"A": "gt=0.1,lt=0.9",
	}

	validate.RegisterStructValidationMapRules(rules, Data{})

	err := validate.Struct(data1)
        err := validate.Struct(data2)
	fmt.Println(err)
	fmt.Println()
}
@ahaooahaz
Copy link
Author

#1145

Floating-point numbers lost precision during the conversion process, which caused the equality of lt and gt to fail to take effect. I modified the code to complete the precision of four decimal places after floating-point numbers to support floating-point numbers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant