我一直試圖簡單地設置一個字段類型爲0到1之間的一個小數,但是無論我有什麼配置,doctrine總是將我的小數位從我的表單字段舍入到最近的整數。如何在symfony2中設置一個小數
我的實體:
/**
* @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;
我的字段類型:
->add('nuetu', 'integer', array(
'scale' => 1,
'attr' => array(
'min' => 0,
'max' => 1,
'step' => '.1',
),
'label' => 'Lef a nuetu',
'required' => false,
))
我的枝杈:
{{ form_row(form.nuetu, {'type': 'number'}) }}
我也試過{{ form_row(form.nuetu) }}
&不使用assert
,並沒有宣佈precision
或scale
在我的實體註釋中。
我的目標是將數字保持爲(0.3或0.8)。
我看了這些問題,但我一直不成功:
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
您的字段類型指定一個'整數'類型。您需要更改爲'號碼'類型。 – ehymel