Rounded decimal in edit form Symfony2 + Doctrine2

前提是你 提交于 2019-12-03 15:08:19

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.

Eric Leschinski

How to set the symfony decimal type precision and scale:

Set it in your entity, like this:

protected $mycolumn;
/**
* @ORM\Column(type="decimal", precision=14, scale=8, nullable=true)
*/

This sets the datatype in the MySQL database:

mycolumn decimal(14,8)

What do scale and precision mean when specifying a decimal field type in Doctrine 2?

In Symfony3.2 you should use scale:

$builder->add('lat', NumberType::class, array('scale' => 8));

This specifies how many decimals will be allowed until the field rounds the submitted value (via rounding_mode). For example, if scale is set to 2, a submitted value of 20.123 will be rounded to, for example, 20.12 (depending on your rounding_mode).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!