Oracle:十进制和舍入

use*_*763 2 sql oracle decimal rounding

我在表0.0821中有一个值,我想将其转换为8.21.

我的SQL查询是 to_char(round(prdll_yr2.rate_chg_pct_qty *100 ),'9.99')

但它返回8.00而不是8.21.

xQb*_*ert 6

to_char(round(0.0821 *100,2 ),'9.99')
Run Code Online (Sandbox Code Playgroud)

to_char(round(prdll_yr2.rate_chg_pct_qty *100,2 ),'9.99')

你错过了在回合中显示的小数位数...... 如果省略默认为0

或者举个例子:

select to_char(round(0.0821 *100,2 ),'9.99') from dual;
Run Code Online (Sandbox Code Playgroud)

结果:8.21

select to_char(round(0.0821 *100),'9.99') from dual;
Run Code Online (Sandbox Code Playgroud)

结果:8.00

----------------------------提供新信息:------------------ ---------

to_char(round(0.0821 *100,2 ),'9,999.99')   
Run Code Online (Sandbox Code Playgroud)

将9,999.99 格式调整 为等于数据库中允许的比例和精度.因此,如果您的值为数字(9,5),则表示4个前导数字后跟5个小数位.由于您乘以100,您可能拥有的最大值是小数点前的6个位置,因此格式为999,999.99,第三个小数位为"Rounded"

  • 在这种情况下你不需要调用`ROUND`,因为你的`TO_CHAR`格式无论如何都会这样做. (2认同)