在python中四舍五入到小数点后2位 [英] round down to 2 decimal in python

查看:38
本文介绍了在python中四舍五入到小数点后2位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要四舍五入,它应该是两位小数.
尝试了以下,

a = 28.266打印轮(a,2)

<块引用>

28.27

但预期值仅为 28.26.

解决方案

似乎您需要 floor:

导入数学math.floor(a * 100)/100.0# 28.26

I need to round down and it should be two decimal places.
Tried the following,

a = 28.266
print round(a, 2)

28.27

But the expected value is 28.26 only.

解决方案

Seems like you need the floor:

import math
math.floor(a * 100)/100.0

# 28.26

这篇关于在python中四舍五入到小数点后2位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆