Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python을 사용하여 부동 숫자를 반올림하는 방법은 무엇입니까?


파이썬 라이브러리의 round() 함수는 숫자를 주어진 위치로 반올림합니다. 다음은 일부 E입니다. 예시 .

>>> round(11.6912,2) # upto second decimal place
11.69
>>> round(11.6912,1) # upto first place after decimal point
11.7
>>> round(11.6912) # rounded to nearest integer
12
>>> round(11.6912,-1)#rounded to ten's place
10.0