ORACLE中的ROUND函数

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值