최종 수정: 에
ROUND
설명
숫자 x를 지정된 자릿수로 반올림합니다.
d를 지정하지 않으면x를 가장 가까운 정수로 반올림합니다.d가 음수이면 소수점 왼쪽에서d로 지정한 자릿수로 반올림합니다.x또는d가null이면null을 반환합니다.d가 열이고 첫 번째 인수의 타입이Decimal이면 결과Decimal의 소수 자릿수는 입력Decimal과 같습니다.
별칭
DROUND
구문
ROUND(<x> [ , <d> ])
매개변수
| 매개변수 | 설명 |
|---|---|
<x> | 반올림할 숫자 |
<d> | 선택 사항. 반올림하여 남길 소수 자릿수 |
예제
select round(2.4);
+------------+
| round(2.4) |
+------------+
| 2 |
+------------+
select round(2.5);
+------------+
| round(2.5) |
+------------+
| 3 |
+------------+
select round(-3.4);
+-------------+
| round(-3.4) |
+-------------+
| -3 |
+-------------+
select round(-3.5);
+-------------+
| round(-3.5) |
+-------------+
| -4 |
+-------------+
select round(1667.2725, 2);
+---------------------+
| round(1667.2725, 2) |
+---------------------+
| 1667.27 |
+---------------------+
select round(1667.2725, -2);
+----------------------+
| round(1667.2725, -2) |
+----------------------+
| 1700 |
+----------------------+
CREATE TABLE test_enhanced_round (
rid int, flo float, dou double,
dec90 decimal(9, 0), dec91 decimal(9, 1), dec99 decimal(9, 9),
dec100 decimal(10,0), dec109 decimal(10,9), dec1010 decimal(10,10),
number int DEFAULT 1)
DISTRIBUTED BY HASH(rid)
PROPERTIES("replication_num" = "1" );
INSERT INTO test_enhanced_round
VALUES
(1, 12345.123, 123456789.123456789,
123456789, 12345678.1, 0.123456789,
123456789.1, 1.123456789, 0.123456789, 1);
SELECT number, dec90, round(dec90, number), dec91, round(dec91, number), dec99, round(dec99, number) FROM test_enhanced_round order by rid;
+--------+-----------+----------------------+------------+----------------------+-------------+----------------------+
| number | dec90 | round(dec90, number) | dec91 | round(dec91, number) | dec99 | round(dec99, number) |
+--------+-----------+----------------------+------------+----------------------+-------------+----------------------+
| 1 | 123456789 | 123456789 | 12345678.1 | 12345678.1 | 0.123456789 | 0.100000000 |
+--------+-----------+----------------------+------------+----------------------+-------------+----------------------+
사용 시 참고 사항
2.5는 3으로 반올림됩니다. 2로 반올림하려면 round_bankers 함수를 사용하세요.