我試圖在液體腳本中顯示浮點值作爲金錢。它似乎只允許你這樣做是爲了數字,但是我不能一個字符串(轉換爲數字儘管在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