Using dot instead of comma when displaying a decim

2019-09-16 13:42发布

In db the field is type decimal and is saved like this 0.5

In Entity the field

/** @ORM\Column(name="precio_x_ticket", type="decimal", scale=2) */

In FormType the field is configure like this

->add('precio_x_ticket','money', array(
                    //'grouping' => true,
                    'currency' => false,
                    'label' => 'Precio por ticket',
                ))

When saving from the form I can save numbers like in this format 0.5 or 0,5 but after saving the number always return this format 0,5 and I wanted to show it like 0.5

My locale is es

Any idea how to solve this using just symfony2.5?

标签: php symfony twig
2条回答
霸刀☆藐视天下
2楼-- · 2019-09-16 14:02

Since I was using {{ form_start(formulario) }} I needed to use

{{ form_widget(formulario.precio_x_ticket, {'value': formulario.precio_x_ticket.vars.value|number_format(2, '.', ' ')}) }}

to show the value in #.## format.

查看更多
Evening l夕情丶
3楼-- · 2019-09-16 14:02

You can use number_format anywhere You want to display a number in custom view. I would not suggest to change Your locale or do other system changes as it would produce unportable and system/configuration dependent code.

查看更多
登录 后发表回答