用于显示销售百分比的 Shopify 功能不起作用

Shopify function for showing percentages of sale doesn't work

我有一个函数应该显示价格下降了多少百分比,但却显示了 -0 %

目前我只有这个

{% if settings.use_saleoff and variant_tmp.compare_at_price > variant_tmp.price %}
    <span>{{'products.product.sale' | t}}</span>
    <span class="price_percentage">-{{ variant_tmp.compare_at_price | minus: variant_tmp.price | times: 100.0 | divided_by: variant_tmp.compare_at_price | money_without_currency | times: 100 | remove: '.0'}}%</span>
{% endif %}

知道这里出了什么问题吗?

正确的方法是:

{% if settings.use_saleoff and variant_tmp.compare_at_price > variant_tmp.price %}
    <span>{{'products.product.sale' | t}}</span>
    <span class="price_percentage">{{ 1.00 | times: variant_tmp.price | divided_by: variant_tmp.compare_at_price | times: 100 | round | minus: 100 }}%</span>
{% endif %}

在第一点,你必须证明数字有小数点。

另外,你有 money_without_currency 会添加类似这样的东西 0 USD 并且字母会破坏之后的数学逻辑。