問題描述
oracle如果存儲number(20,2)數據,0數據庫中為0.00,2.1數據庫中為2.10,3.88存儲為3.88,
如果直接從數據庫中取出對應顯示為:
0 2.1 3.88 保留兩位小數會發生變化,如果需要和數據庫保持一致:
解決方法
保留兩位有效小數的方法:
SELECT TO_CHAR(3.2,'FM99999999999990D00') FROM DUAL
廢話太多了,直接上例子:
參考實例:
select to_char(a, '99D90'),
to_char(a, '90D90'),
to_char(a, 'FM90D99'),
rtrim(to_char(a, 'FM90D99'), to_char(0, 'D'))
from (
select 50 a from dual
union all select 50.57 from dual
union all select 5.57 from dual
union all select 0.35 from dual
union all select 0.4 from dual
)
order by a;
TO_CHA TO_CHA TO_CHA RTRIM(
------ ------ ------ ------
.35 0.35 0.35 0.35
.40 0.40 0.4 0.4
5.57 5.57 5.57 5.57
50.00 50.00 50. 50
50.57 50.57 50.57 50.57