0

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 ?

Martin Fasani
  • 825
  • 7
  • 20
  • 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 Oct 07 '15 at 09:38

1 Answers1

0

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

0.009 which is equivalent 0.01

Snoozer
  • 585
  • 1
  • 8
  • 16
  • The formType it's money type, without "scale" defined. I also tried to update the DB field to float(6,3) that allow me to save 0.009 directly in mysql. The only question is if there is something wrong with my float definition in Doctrine http://stackoverflow.com/questions/7296027/doctrine-2-2-decimal-places-on-a-float – Martin Fasani Oct 07 '15 at 17:12
  • ORM column annotation have options "precision" , "scale". chapter 4.3 : [link](http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html). – Snoozer Oct 08 '15 at 07:19