[파이썬] - 반올림/올림/내림/버림_소수점 구하기 (cf. f-string)

zsunny·2022년 6월 22일
0

[Python] 문법

목록 보기
4/18

🔎 반올림 - round( )

n = 1.2345
round(n)			// 1
round(n, 2)			// 1.23 반올림해 2번째 자릿수까지 출력
round(n, 3)			// 1.235 반올림해 3번째 자릿수까지 출력

🔎 올림 - ceil( )

import math
math.ceil(12.345)		// 13

🔎 내림 - floor( )

import math
math.floor(12.345)		// 12

🔎 버림 - trunc( )

import math
math.trunc(12.345)		// 12

🔎 소수점 자릿수 지정 - f-string

n = 1.2345
print(f"{n:.3f}%")		// 1.234% 출력
profile
매일 성장하는 예비 웹 개발자 🌱

0개의 댓글