2

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

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

但它返回 8.00 而不是 8.21。

4

1 回答 1

6
to_char(round(0.0821 *100,2 ),'9.99')

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;

结果:8.21

select to_char(round(0.0821 *100),'9.99') from dual;

结果:8.00

----------------------------给出新信息:------ ---------

to_char(round(0.0821 *100,2 ),'9,999.99')   

将 9,999.99格式调整 为等于数据库中允许的比例和精度。因此,如果您的值为 Numeric(9,5),则这意味着 4 个前导数字后跟 5 个小数位。由于您要乘以 100,因此您可能拥有的最大值是小数点前 6 个位置,因此 999,999.99 的格式和小数点后第三位将是“四舍五入”

于 2013-05-01T19:01:25.267 回答