显示十进制数时使用点代替逗号 [英] Using dot instead of comma when displaying a decimal number
问题描述
在 db 中,字段类型为十进制,并像这样保存为 0.5
In db the field is type decimal and is saved like this 0.5
在实体字段
/** @ORM\Column(name="precio_x_ticket", type="decimal", scale=2) */
在 FormType 中,字段是这样配置的
In FormType the field is configure like this
->add('precio_x_ticket','money', array(
//'grouping' => true,
'currency' => false,
'label' => 'Precio por ticket',
))
从表单保存时,我可以以这种格式保存数字 0.5 或 0,5,但保存数字后总是返回这种格式 0,5,我想将其显示为 0.5
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
我的语言环境是 es
知道如何仅使用 symfony2.5 来解决这个问题吗?
Any idea how to solve this using just symfony2.5?
推荐答案
自从我使用 {{ form_start(formulario) }}
我需要使用
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.
这篇关于显示十进制数时使用点代替逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!