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)
 change .000 to percentage.

Author  Topic 

hbadministrator
Posting Yak Master

120 Posts

Posted - 2013-06-19 : 15:39:20
current field salesgm.gp shows the current results.

gp
.045364
.574345
I want it to show 2 decimal places
45.26
57.43

robvolk
Most Valuable Yak

15732 Posts

Posted - 2013-06-19 : 15:50:27
SELECT ROUND(gp*100.0,2) gp_pct FROM salesgm
Go to Top of Page

hbadministrator
Posting Yak Master

120 Posts

Posted - 2013-06-19 : 15:57:05
thought the same thing, but get this. The rounding is good but I need to drop those other 4 0's.

ROUND(HB_JL_salesgm.GP * 100.0, 2)

34.750000
41.320000
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-06-19 : 17:23:15
Cast it to decimal(nn,2), for example:
SELECT CAST(ROUND(gp*100.0,2) AS DECIMAL(19,2)) gp_pct FROM salesgm
And, you do know someone will reply to this thread suggesting that you do this kind of formatting in the presentation layer, don't you?
Go to Top of Page

hbadministrator
Posting Yak Master

120 Posts

Posted - 2013-06-20 : 07:43:59
That is actually what I ended up doing. :)
Go to Top of Page

hbadministrator
Posting Yak Master

120 Posts

Posted - 2013-06-20 : 07:44:44
I was trying to get it all formatted in the back end but then said screw this I'll do it in the front end.
Go to Top of Page
   

- Advertisement -