0
votes

I would like to know about this particular validation behaviour, although is more out of curiosity than to solve a real life problem, I'm interested to know the answer.

Entity property price is defined as:

/**
 * @ORM\Column(name="price", type="float", nullable=false)
 */   

In the Symfony manual targeting 2.7, range min and max options are 'integer' types. But actually using a float, it does work as expected:

#validation.yml
Project\MyBundle\Entity\Product:
    properties:
        price:
           - Range:
                min: 0.01
                max: 12.90
                minMessage: Price can't be lower than 0,01€
                maxMessage: Price can't be lower than 12,90€

enter image description here

max validation works without any problem making any value higher than 12,90 fail as seen in the picture. min validation does not:

Entering 0,009 will pass validation although is minor than 0,01.

Is there any reason that min and max values are documented as type: integer but work to validate float values ? Has anyone a valid answer for this one ?

1
Wild guess: Are you rounding up to the second place after the coma so that 0.009 becomes 0.01? Another thing to look into would be float precision. - k0pernikus

1 Answers

0
votes

Price type has a precision point 2, so your number is rounded

0.009 which is equivalent 0.01