您能帮我吗????
如何将烧瓶烧瓶中的小数点后两位数字传递给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'),]]
我该如何解决?
该值可以,但是格式不正确。
您可以将round函数用于python中的精度。例如,
average = 2.34242433
average = round(average,2)
print(average)
输出: 2.34
因此在application.py
文件中,返回为>>
average=round(average,2)