# \[수학] 반올림 / 올림 / 버림

### 코드

{% code title="값을 반올림할 때" %}

```
@수학 (값) 반올림
```

{% endcode %}

{% code title="값을 올림할 때" %}

```
@수학 (값) 올림
```

{% endcode %}

{% code title="값을 내림할 때" %}

```
@수학 (값) 내림
```

{% endcode %}

{% code title="특정 자리까지의 반올림/올림/내림 값을 보여줄 때" %}

```
@수학 (값) 소수점 (숫자)번째까지 반올림/올림/내림
```

{% endcode %}

***

### 설명

값에 대한 반올림 / 올림 / 버림 결과를 반환합니다.

* 반올림 :  $$\lfloor x + 0.5 \rfloor$$
* 올림 : $$\lceil x \rceil$$
* 버림 : 소수점을 0 방향으로 깎아내는 절단(Truncation) 방식으로 음수 영역에서는 바닥 함수 $$\lfloor x \rfloor$$ 와  차이가 있어요.

***

### 주의사항

* 수학 코드를 쓸 때는 앞에 `@수학`을 써야 해요.
* 반올림 기준은 0.5예요.

***

### 파이썬 대응 코드

```
import math
round(x)
math.ceil(x)
math.floor(x)
```

***

### 예시

{% code title="예시 코드" %}

```
# 반올림
@수학 3.7 반올림 보여주기
@수학 3.2 반올림 보여주기
@수학 -3.3 반올림 보여주기

# 올림
@수학 3.1 올림 보여주기

# 버림
@수학 3.9 버림 보여주기

# 특정 소수 자리까지 보여주기
(@수학 3.735323 소수점 2번째까지 반올림) 보여주기
```

{% endcode %}

{% code title="예시 코드의 결과" %}

```
4  # 3.7 반올림
3  # 3.2 반올림
-3 # -3.3 반올림
4  # 3.1 올림
3  # 3.9 버림
3.74 #소수점 2번째까지 반올림
```

{% endcode %}

***

### 검색 키워드

수학, 반올림, 올림, 버림


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codebook.horang.it/math/undefined.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
