I've been trying to simply set a field type to a decimal between 0 and 1 however no matter the configuration I have, doctrine always rounds my decimal from my form field to the nearest whole number.
My entity:
/**
* @var integer
*
* @Assert\Range(
* min=0,
* max=1,
* minMessage = "this must be greater than or equal to 0.",
* maxMessage = "this must be less than or equal to 1."
* )
* @ORM\Column(name="nuetu", type="decimal", precision=2, scale=1, nullable=true)
*/
private $nuetu;
My Field Type:
->add('nuetu', 'integer', array(
'scale' => 1,
'attr' => array(
'min' => 0,
'max' => 1,
'step' => '.1',
),
'label' => 'Lef a nuetu',
'required' => false,
))
My Twig:
{{ form_row(form.nuetu, {'type': 'number'}) }}
I've also tried {{ form_row(form.nuetu) }}
& without using assert
and without declaring precision
or scale
in my entity annotations.
My goal is to persist the number to the database as (0.3 or 0.8).
I've looked at these questions but I have been unsuccessful:
What is the right way to define annotation for DECIMAL type in Doctrine2
Rounded decimal in edit form Symfony2 + Doctrine2
http://symfony.com/doc/2.7/reference/forms/types/integer.html
http://symfony.com/doc/2.7/reference/forms/types/number.html#scale