简体   繁体   English

Drupal 8 Webform 中的 number_format 用法

[英]number_format usage in Drupal 8 Webform

I would like to format the numbers being displayed in a "Computed Twig" element in Drupal 8 Webform.我想格式化显示在 Drupal 8 Webform 的“Computed Twig”元素中的数字。 I've tried Twig's "number_format" filter, but it does not work.我试过 Twig 的“number_format”过滤器,但它不起作用。 I have this:我有这个:

{{ (data.auswahl_oder_eingabe) * 202 / 1000000 * 25|number_format(2, ',', '.') }}

I would like to have only two decimals, the dot as a thousands separator and the comma as a decimal point.我希望只有两位小数,点作为千位分隔符,逗号作为小数点。 But I always get something like this:但我总是得到这样的东西:

53.025 53.025

So three decimals and the dot as a decimal separator.所以三位小数和点作为小数点分隔符。 The format I would like to have in this case would be: 53,03 No matter what I write in that "number_format" definition, the result doesn't change.在这种情况下我想要的格式是:53,03 无论我在那个“number_format”定义中写什么,结果都不会改变。 Does this filter work at all in Drupal 8.7.7?这个过滤器在 Drupal 8.7.7 中是否有效? Or is there a mistake I made somewhere in the markup?还是我在标记的某处犯了错误?

I believe that your filter is only applying to the 25 not the entire calculated value.我相信您的过滤器仅适用于25而不是整个计算值。 Try something like this:尝试这样的事情:

{% set calculated = data.auswahl_oder_eingabe * 202 / 1000000 * 25 %}
{{ calculated|number_format(2, ',', '.') }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM