【发布时间】:2017-04-17 17:20:52
【问题描述】:
我一直试图简单地将字段类型设置为 0 到 1 之间的小数,但是无论我的配置如何,原则总是将我的小数从我的表单字段四舍五入到最接近的整数。
我的实体:
/**
* @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
【问题讨论】:
-
您的字段类型指定了
integer类型。需要改成number类型。
标签: php symfony doctrine-orm fieldtype