更改数字格式 更改数字值
我有一个“salaire”对象,显示在树枝一侧。
{{ salaire.getMontant_euros_revalorise() }}
注意:salaire.getMontant_euros_revalorise() 是一个浮点数。
它显示:
20,685.05
这是美国显示,我想将其更改为欧洲显示,这意味着逗号是一个点,点是逗号。
所以我尝试使用这个:
{{ salaire.getMontant_euros_revalorise()|number_format(2, ",", ".") }}
不幸的是,它改变了数字的值。它显示:
20,00
所以从两万六百八十五点零五我们到二十。
我不知道为什么会这样做,但有人知道如何正确更改点和逗号符号吗?最后有:
20.685,05
I have a "salaire" object that I display on the twig side.
{{ salaire.getMontant_euros_revalorise() }}
Note: salaire.getMontant_euros_revalorise() is a float.
it displays this :
20,685.05
It is an american display, I would like to change it to a european display meaning that the comma is a point and the point a comma.
So i tried to use this :
{{ salaire.getMontant_euros_revalorise()|number_format(2, ",", ".") }}
Unfortunatly, it changes the value of the number. It displays this:
20,00
So from twenty thousand six hundred eighty five point zero five we go to twenty.
I dont know why it does that but does somebody know how to chnage correctly the point and comma signs ? having at the end :
20.685,05
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
getMontant_euros_revalorise
实际上返回20,685.05
而没有任何修改,那么您存储的是一个字符串
,而不是浮点数。因此,解决此问题的最佳方法是确保将数据存储为实数/浮点而不是字符串,或者确定代码已经在何处修改该值。如果这是不可能的,那么您需要替换 < code>comma 在应用过滤器之前。
演示
If
getMontant_euros_revalorise
actually returns20,685.05
without any modification, then you have stored astring
, not a float. So the best way to solve this, is to be sure you store the data as a real number/float rather than a string or determine where your code is already modifying the valueIf this is not possible, then you would need to replace the
comma
before applying the filter.demo