ORACLE中的ROUND函数

来源:互联网 发布:多元高斯分布知乎 编辑:程序博客网 时间:2024/04/29 12:16

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