Python
[python 공부] 소수 반올림, 올림, 버림
kyeongjun-dev
2021. 7. 3. 16:31
반올림
round 사용
>>> round(1.123)
1
>>> round(1.123, 0)
1.0
>>> round(1.123, 1)
1.1
>>> round(1.123, 2)
1.12
>>> round(1.123, 3)
소수가 아닌 수의 반올림
>>> round(1234, -1)
1230
>>> round(1234, -2)
1200
>>> round(1234, -3)
1000
올림, 내림, 버림
>>> import math
>>> math.ceil(1.123) # 올림
2
>>> math.floor(1.123) # 내림
1
>>> math.trunc(1.123) # 버림
1