Jak*_*kin 1 django django-templates stripe-payments
我正在使用 stripe 通过 django Web 应用程序处理付款。
数据库中的价格以十进制格式存储,例如 100.00
Stripe 将其视为 $1,并忽略小数点右侧的所有内容。
将此数字传递给 Stripe 时,我需要删除小数点。
我可以在 django 模板中执行此操作吗?
使用浮点格式过滤器,您可以执行以下操作:
{{ value.context|floatformat }}
Run Code Online (Sandbox Code Playgroud)
编辑
特别有用的是传递 0(零)作为参数,它将浮点数四舍五入到最接近的整数。
value Template Output
34.23234 {{ value|floatformat:"0" }} 34
34.00000 {{ value|floatformat:"0" }} 34
39.56000 {{ value|floatformat:"0" }} 40
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3164 次 |
| 最近记录: |