显示小数时使用点而不是逗号

Using dot instead of comma when displaying a decimal number

在 db 中,该字段是十进制类型,并像这样保存 0.5

在实体字段中

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

在 FormType 中,字段是这样配置的

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

当从表格中保存时,我可以像 0.5 或 0,5 这样的格式保存数字,但在保存数字后总是 return 这种格式 0,5 我想显示它像 0.5

我的语言环境是 es

知道如何仅使用 symfony2.5 解决这个问题吗?

您可以在任何您想在自定义视图中显示数字的地方使用 number_format。我不建议更改您的 locale 或进行其他系统更改,因为它会产生不可移植且 system/configuration 依赖的代码。

因为我使用的是 {{ form_start(formulario) }} 我需要使用

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

以#.## 格式显示值。