Rounded decimal in edit form Symfony2 + Doctrine2

decimal, doctrine-orm, symfony

Solution

Maybe the problem is not due to your doctrine mapping. Look at this reference documentation for NumberType.

It is what you use? You probably have to change the precision.

Problem

How do I set the decimal precision and scale within the symfony2 entity? I've defined latitude in longitude fields using decimal data type in my entity like this: ``` /** * @ORM\Column(type="decimal", precision="10", scale="6", nullable=true) */ protected $latitude; ``` When persisting new object it saves decimal correctly (I can see 52.406374 in phpMyAdmin). However when displaying edit form the number is rounded to 52,406 and after updating it is stored in mysql as 52.406000. Probably something is wrong with my Doctrine configuration, but I don't know what. Why is the latitude and longitude getting rounded? Found a solution: Symfony's Form component renders decimal form field as type="text". When using: ``` ->add('latitude', 'number', array( 'precision' => 6, )) ``` It is rendered properly. The thread from comment doesn't describe my problem. I guess they have already fixed bug with 'convert to float' precision. When I was displaying latitude in twig template it was showing proper (not rounded) value.

Original source

Related problems