Tuesday, April 28, 2020

MaxValueValidator and small floats

I have a form field: 
H2mix_inp = forms.DecimalField(label=mark_safe('<strong>H2mix (0.02 to 0.5)</strong> The mixing ratio of molecular hydrogen in the (otherwise) N2 background gas. Expressed as H2/(H2+N2.'),
           validators=[MinValueValidator(0.02),MaxValueValidator(max(H2mix))])

When I enter 0.02 or 0.02, I Geta validation error 
  • Ensure this value is greater than or equal to 0.02.
My guess is that this has to do with floating point equality issues. Has anyone experienced this behavior before, and how do I fix it?

Marshall

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e47c1a28-a4d6-444d-8114-27b86f9bd5af%40googlegroups.com.

No comments:

Post a Comment