| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- GitLab
- AI
- docker
- pytorch
- list
- 책갈피
- file
- KAKAO
- LLM
- Database
- format
- Laravel
- Linux
- Python
- Flask
- pandas
- PostgreSQL
- TORCH
- ubuntu
- numpy
- git
- Package
- Paper
- Container
- judge
- Mac
- Windows
- evaluation
- DB
- Converting
Archives
- Today
- Total
Daily Develope
[Python] 반올림 본문
일반 반올림 (오사오입)
python의 기반 round 함수를 사용하는 경우 오사오입이 적용된다. (올림 자리수가 5인 경우 그 앞자리가 홀수면 올리고 짝수면 내림)
print(round(3.5, 0)) # 출력값 : 4
print(round(4.5, 0)) # 출력값 : 4
decimal 사용 (사사오입)
일반적으로 알고있는 반올림 방법
import decimal
ctx = decimal.getcontext()
ctx.rounding = decimal.ROUND_UP
print(round(decimal.Decimal(3.5), 0)) # 출력값 : 4
print(round(decimal.Decimal(4.5), 0)) # 출력값 : 5
주의사항 : 반올림 후 결과의 type은 Decimal 이므로 필요에 따라 형변환 수행.
'Develope > Python' 카테고리의 다른 글
| [Poetry] Poetry 설치 및 기본 명령어 on Mac (2) | 2025.03.05 |
|---|---|
| [Python] Install PyTorch & Error Handling on Mac (0) | 2025.02.26 |
| [Python] 엑셀 파일 다루기 with Pandas (0) | 2024.01.22 |
| [Python] Pickle library (object serialization) (1) | 2023.10.17 |
| [Python] Postgresql 연동 / 연결 코드 샘플 (0) | 2023.10.03 |
Comments