파이썬 소수점 자리수 제한하는 방법

yurimLee·2023년 1월 11일
0

1. round()

num = 3.14159265358979
print(round(num, 2))
3.14

2. f-string

num = 3.14159265358979
print(f"{num:.2f}")
3.14

3. "{}".format()

num = 3.14159265358979
print("{:.2f}".format(num))
3.14

4. format()

num = 3.14159265358979
print(format(num, ".2f"))
3.14

5. Operater %

num = 3.14159265358979
print('%.2f' % num)
3.14

참고
https://jsikim1.tistory.com/226

0개의 댓글