Thread: Trailing 0's
View Single Post

   
  #6 (permalink)  
Old 02-28-2008, 06:58 PM
Gert-Jan Strik
 
Posts: n/a
Default Re: Trailing 0's

create table #t (c decimal(10,6))
insert into #t values (45.34)
insert into #t values (27.7)
insert into #t values (55)
insert into #t values (101.1)

select c,
replace(rtrim(replace(
replace(rtrim(replace(
cast(c as varchar(12))
,'0',' ')),' ','0')
,'.',' ')),' ','.')
from #t

drop table #t

Gert-Jan

Jason wrote:
>
> I have a column defined as DECIMAL(10,6). I want to display it as a
> string but I do not want the trailing zeros. I cannot seem to get CAST
> or CONVERT or STR to exclude the zeros.
>
> Examples:
> 45.340000 --> 45.34
> 27.700000 --> 27.7
> 55.000000 --> 55
>
> Is there a function that will do this or do I need to write my own?

Reply With Quote