How to check in Zend Framework if float / double is equal to or greater / less than min?

I have a simple question for which I did not find an answer, and this

How can I use the built-in Zend Validator to check if the float / dobule is greater than or equal to min?

I was already looking for an answer that matches my query, and I found this question by the GreaterOrEqual validator in the Zend Framework , but mine is a little different. In addition, I know that I can create my own validator or copy one of those that are on the Internet, like this Greater Than or Equal Validator , but I would like to know how I can perform this check with the built-in validators.

This is an example that will help you better understand.

If I had an integer, I could achieve this goal as follows:

$Validators = array(new Zend_Validate_Int(), new Zend_Validate_GreaterThan($min - 1)); // Validate the number 

Instead, if I had a float, I cannot do this trick, and as many programmers know, trying to do dirty things with a float can create a lot of problems due to the rounding problem ( What every computer scientist needs to know about arithmetic with floating point ).

Thank you all

+4
source share
3 answers

After trying many times, I came to the conclusion that in fact (Zend Framework version 1.11) it is not possible to do this using the built-in validators (as Phil suggested).

I really hope they add this validator in future releases.

+2
source

This is not exactly what you asked for, but I find it the easiest: the "inlusive" key.

  $number->addValidator('Float'); $number->addValidator('Between', false,array('min' => '5,5', 'max' => $greatest_number+1, 'inclusive' => true)); 

Here you have all the validators:

Zend_Validate_Abstract reference

therefore, the answer for your question is “no,” for pop-up messages there is no more meaningful or even validator.

+2
source

How about using

new Zend_Validate_Callback (function ($ value) {if ($ value> = 1) {return true;} return false;});

-1
source

All Articles