Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Decimal Places

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2011-12-08 : 15:26:16

I've been trying to find a way to format a number.

It should always show two decimal places.

any zeros after that two places, remove.

So, 1.2000000 = 1.20
1.200056 = 1.200056
1.200440 = 1.20044

Just can't find a good way to do this.

Thanks for any imput --

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2011-12-08 : 17:24:39
While this could be accomplished at the SQL level by converting the number to a string and applying some logic, these types of display issues shoulkd really be done at the application side.

=======================================
Faced with the choice between changing one's mind and proving that there is no need to do so, almost everyone gets busy on the proof. -John Kenneth Galbraith
Go to Top of Page

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2011-12-08 : 17:47:19
I agree. But it's an xml I am creating.
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2011-12-08 : 17:55:44
In that case...[CODE]cast(
case
when MyColumn = cast(MyColumn as Decimal(15, 2))
then cast(MyColumn as Decimal(15, 2))
else MyColumn
end
as varchar(20))[/CODE]Untested.

=======================================
Faced with the choice between changing one's mind and proving that there is no need to do so, almost everyone gets busy on the proof. -John Kenneth Galbraith
Go to Top of Page
   

- Advertisement -