python 四捨五入

1.round 

    四捨五入(真實是“四捨六入五成雙”)

round(3.4)
==>3
round(3.5)
==>4
# 指定小數位數取值
round(3.5554, 3)
==>3.555
round(3.5555, 3)
==>3.556

# 取第幾位,如果取得那位後面是5,取得那位是奇數,則舍, 取得那位是偶數,則入
print(round(3.46575, 4))
==>3.4657

print(round(3.465465, 5))
==>3.46547

2.math

a. 取大

import math


math.meil(3.4)
==>4
math.meil(3.6)
==>4

b.取小

import math


math.floor(3.4)
==>3
math.floor(3.6)
==>3

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章