ROUND (number)
语法
用法
ROUND returns n rounded tointeger places to the right of the decimal point. If you omitinteger,
then n is rounded to 0 places. The argumentinteger can be negative to round off digits left of the decimal point.
n can be any numeric datatype or any nonnumeric datatype that can be implicitly converted to a numeric datatype. The argumentinteger must be an integer.
If you omitinteger, then the function returns the same datatype as the numeric datatype of the argument. If you includeinteger, then the function returnsNUMBER.
For NUMBER values, the value n is rounded away from 0 (for example, tox+1 whenx.5 is positive
and tox-1 whenx.5 is negative).(数值数据精确到离0更远的那一端) ForBINARY_FLOAT andBINARY_DOUBLE values, the function rounds to the nearest even
value. (单精度浮点数或双精度浮点数精确到最近的偶数)Please refer to the examples that follow.
范例
The following example rounds a number to one decimal point(精确到一位小数):
SELECT ROUND(15.193,1), ROUND(-15.193,1) FROM DUAL;
ROUND(15.193,1) ROUND(-15.193,1)
--------------- ----------------
15.2 -15.2
SELECT ROUND(15.149,1), ROUND(-15.149,1) FROM DUAL;
ROUND(15.149,1) ROUND(-15.149,1)
--------------- ----------------
15.1 -15.1
The following example rounds a number one digit to the left of the decimal point(精确到十位):
SELECT ROUND(15.193,-1) "Round" FROM DUAL;
Round
----------
20
SELECT ROUND(14.999, -1) "Round" FROM DUAL;
Round
----------
10
The following examples illustrate the difference between rounding NUMBER and floating-point number values.NUMBER values are rounded up (for positive values), whereas floating-point numbers are rounded toward the nearest even value(数值数据精确到离0更远的那一端,单精度浮点数或双精度浮点数精确到最近的偶数):
SELECT ROUND(1.5), ROUND(2.5) FROM DUAL;
ROUND(1.5) ROUND(2.5)
---------- ----------
2 3
SELECT ROUND(1.5f), ROUND(2.5f) FROM DUAL;
ROUND(1.5F) ROUND(2.5F)
----------- -----------
2.0E+000 2.0E+000
以下为自测部分:
SELECT ROUND(-1.55, 1), ROUND(1.55, 1) FROM DUAL;
ROUND(-1.55,1) ROUND(1.55,1)
-------------- -------------
-1.6 1.6
SELECT ROUND(-1.55f, 1), ROUND(1.55f, 1) FROM DUAL;
ROUND(-1.55F,1) ROUND(1.55F,1)
--------------- --------------
-1.5 1.5
本文详细介绍了ROUND函数的使用方法,包括其语法、参数说明及不同数值类型下的取整规则,并通过多个示例展示了如何精确到不同的小数位或整数位。
550

被折叠的 条评论
为什么被折叠?



