Reputation: 281
I have these values
ROWA
-------
0.23
0.2350
0.1000
1.250
1200
1.300
I wanted to convert to a format where only decimal trailing zero are remove I tried using this
select cast(RowA as decimal(18,3)) from dual.
But the result remove the leading zero of the decimal.
ROWA
-------
.23
.235
.1
1.25
1200
1.3
How do I convert to
ROWA
-------
0.23
0.235
0.1
1.25
1200
1.3
Upvotes: 1
Views: 9165
Reputation: 26220
Here is the most concise solution I'm currenly aware of:
rtrim(to_char(rowa, 'FM999999999999999990.999'), '.')
Taken from my another detailed answer.
Upvotes: 1
Reputation: 60312
Your samples show two different formats - one for decimal numbers, and a different one for integers.
with sampledata as
(select 0.23 as rowa from dual
union all select 0.2350 from dual
union all select 0.1000 from dual
union all select 1.250 from dual
union all select 1200 from dual
union all select 1.300 from dual
)
select TO_CHAR(rowa
,CASE WHEN rowa = TRUNC(rowa)
then 'fm999999999999999990'
else 'fm999999999999999990D999'
end) as rowa
from sampledata;
ROWA
=====
0.23
0.235
0.1
1.25
1200
1.3
Upvotes: 5