Format Price Tags

AnQiCMS v3.5.6 version and above supports, old versions do not support

Due to the fact that the price field of AnQiCMS uses fen as the unit, it is not suitable to be displayed directly in the template, so the price needs to be converted to yuan before output. The default output is complex and needs to be converted to float64 first, then divided by 100, and then formatted to two decimal places.{%- set price = item.Price|float/100 %}<span>${{price|floatformat:2}}</span>Now it supports direct formatting of the price field to the specified formatted output. Tag keywords:priceFormat.

How to use: {{priceFormat(price, “format”)}}. The price is in cents, such as1880Format supports printf format, such as{{priceFormat(item.Price, "%.2f")}}And predefined values:int|one|two/0|1|2Default to 2 decimal places.

Example Code

{% set price = 1880 %}

{# 格式化 为 保留两位小数点的价格 #}
<div>{{priceFormat(price)}}</div>
{# 或者 #}
<div>{{priceFormat(price, 2)}}</div>
<div>{{priceFormat(price, "two")}}</div>
<div>{{priceFormat(price, "%.2f")}}</div>


{# 格式化 为 只保留一位小数点价格 #}
<div>{{priceFormat(price, 1)}}</div>
<div>{{priceFormat(price, "one")}}</div>
<div>{{priceFormat(price, "%.1f")}}</div>


{# 格式化 为 只保留整数部分价格 #}
<div>{{priceFormat(price, 0)}}</div>
<div>{{priceFormat(price, "int")}}</div>
<div>{{priceFormat(price, "%.0f")}}</div>