Algorithm/Python

[파이썬] - 반올림, 내림, 올림

say! 2022. 8. 26. 17:25
728x90

# 반올림

round() 함수 사용하기

round(1.6)    # 2 출력
round(1.789, 2)    # 1.79 출력
round(11.789, -1)    # 10 출력

 

# 내림

import math 후 math.floor() 사용하기

import math
math.floor(3.1415)    # 3 출력
 

# 올림

import math 후 math.ceil() 사용하기

import math
math.ceil(3.1415)    # 4 출력

 

 

How do you round UP a number?

How does one round a number UP in Python? I tried round(number) but it rounds the number down. Example: round(2.3) = 2.0 and not 3, as I would like. The I tried int(number + .5) but it round the ...

stackoverflow.com