■ Context 클래스의 rounding 속성을 사용해 올림 연산을 설정하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import decimal decimal1 = decimal.Decimal("3.14") decimal2 = decimal.Decimal("7") print(decimal1 / decimal2) # 0.4485714285714285714285714286 context = decimal.getcontext() context.prec = 7 context.rounding = decimal.ROUND_CEILING decimal3 = decimal1 / decimal2 print(decimal3) # 0.4485715 |
※ 설정 가능 옵션값
·ROUND_CEILING
·ROUND_DOWN
·ROUND_FLOOR
·ROUND_HALF_DOWN
·ROUND_HALF_EVEN
·ROUND_HALF_UP
·ROUND_UP
·ROUND_95UP