반올림 round
>>> n = 7/15
>>> n
0.4666666666666667
>>> round(n,2)
0.47
>>> round(n,4)
0.4667
>>> round(n)
0
>>> type(round(n))
<class 'int'>
math.ceil(i) : 올림
math.floor(i) : 내림
math.trunc(i) : 버림
import math
>>> math.ceil(12.2)
13
>>> math.ceil(12.6)
13
>>> math.floor(12.2)
12
>>> math.floor(12.6)
12
>>> math.trunc(12.2)
12
>>> math.trunc(12.6)
12
'program > python' 카테고리의 다른 글
[python] 사전 dictionary (0) | 2024.01.28 |
---|---|
[python] for문 Range (0) | 2024.01.28 |
[python] list 정렬 sort sored (1) | 2024.01.28 |
[python] 리스트 함수 (0) | 2024.01.28 |
[python] while, if, elif (0) | 2024.01.28 |