如何将flask-python的小数点后两位传递给html?

问题描述 投票:0回答:1

您能帮我吗????

如何将烧瓶烧瓶中的小数点后两位数字传递给html?

我在application.py中输入了以下代码:

平均值= db.execute(“从评论中选择AVG(分数),在book_id =:book_id”,{“ book_id”:book_id})。fetchall()返回render_template(“ comments.html”,book = book,statement = statements,average = average)

而且我输入了html文件:.... jinjer

{{平均}}

我期望值= 3,但结果是:

[(Decimal('3.0000000000000000'),]]

我该如何解决?

该值可以,但是格式不正确。

python flask floating-point decimal
1个回答
0
投票

您可以将round函数用于python中的精度。例如,

average = 2.34242433
average = round(average,2)
print(average)

输出: 2.34

因此在application.py文件中,返回为>>

average=round(average,2)

© www.soinside.com 2019 - 2024. All rights reserved.