我试图在液体脚本中显示浮点值作为金钱。它似乎只允许你这样做是为了数字,但是我不能一个字符串(转换为数字尽管在SO如下:)Liquid Script:将字符串转换为数字以显示为钱
{% 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 |钱: “GBP”}}
但这返回一个错误:
test show above as money: System.Linq.Enumerable+d__112`1[System.String]
感谢所有帮助
只是为了澄清所需的输出是'testnumeric作为金钱的输出:£202.24',但我需要这适用于一个字符串,谢谢 – Blingers