2017-04-17 4 views
0

필자는 필드 유형을 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, 
     )) 

내 나뭇 가지 : 나는 또한 assert를 사용하지 않고 precision를 선언하지 않고 또는 {{ form_row(form.nuetu) }} &을 시도했습니다

{{ form_row(form.nuetu, {'type': 'number'}) }} 

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

+0

필드 유형이 '정수'유형을 지정하고 있습니다. 'number' 타입으로 변경해야합니다. – ehymel

답변

0

정수는 소수가 아닙니다. 언급 된 ehymel과 같은 숫자를 사용하십시오 :

->add('nuetu', NumberType::class, array(
    'scale' => 1, 
    'attr' => array(
     'min' => 0, 
     'max' => 1, 
     'step' => '.1', 
    ), 
    'label' => 'Lef a nuetu', 
    'required' => false, 
)) 

위의 사항이 작동합니다.