PHP - BUG with filter_var and FILTER_VALIDATE_FLOAT

Posted by Samuele on Stack Overflow See other posts from Stack Overflow or by Samuele
Published on 2010-05-28T15:10:58Z Indexed on 2010/05/28 15:12 UTC
Read the original article Hit count: 178

Filed under:
|
|

I think there is a bug in this filter_var or maybe I'm doing something wrong: Try this:

        $options = array(
            'options' => array(
                'default' => 3,
                'min_range' => 1000.0,
                'max_range' => 5000.6,
            )
        );

  $VariableValue2 = 5698;
  $VariableValue4 = 5698.2;

  $chicco3 = filter_var($VariableValue2, FILTER_VALIDATE_INT, $options);
  $chicco4 = filter_var($VariableValue4, FILTER_VALIDATE_FLOAT, $options);

It suppose to don't validate it... Infact the value: 5698 is greater than 5000.6!!!! But with FILTER_VALIDATE_INT it work FINE!! It return 3 that is the default value in case it don't validate it... PERFECT...

Instead, with FILTER_VALIDATE_FLOAT it validate it... It return 5698.2!!! I'm doing something wrong???

Thank you to everybody...

Samuele

© Stack Overflow or respective owner

Related posts about php

Related posts about range