我正在尝试将浮点值显示为液体脚本中的货币。它似乎只允许您对数字执行此操作,但是我无法将字符串转换为数字(尽管遵循以下关于 SO 的建议:)
{% assign teststring = '202.2400' %}
{% assign testnumeric = 202.2400 %}
teststring: {{ teststring }} <br/>
testnumeric: {{ testnumeric }} <br/>
teststring as money: {{ teststring |money: "GBP" }} <br/>
testnumeric as money: {{ testnumeric |money: "GBP" }} <br/>
{% assign testStringAsNumeric = teststring | plus: 45 %}
test convert teststring to numeric: {{ testStringAsNumeric }} <br/>
test show above as money: {{ testStringAsNumeric |money: "GBP" }}
输出是:
teststring: 202.2400
testnumeric: 202.24
teststring as money: 202.2400
testnumeric as money: £202.24
test convert teststring to numeric: 202.24000
test show above as money: 202.24000
我想要的是将字符串值(teststring)显示为钱。所以我需要转换成一个数字,然后显示为钱。
我也尝试过时间过滤器,例如
{% assign testStringAsNumeric = teststring | times: 1 %}
上面的测试显示为金钱:{{ testStringAsNumeric |money: "GBP" }}
但这会返回一个错误:
test show above as money: System.Linq.Enumerable+d__112`1[System.String]
谢谢你的帮助