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 2005 Forums
 Transact-SQL (2005)
 How to get result with decimal places?

Author  Topic 

ryanlcs
Yak Posting Veteran

62 Posts

Posted - 2010-01-28 : 21:27:31
How can I get the result with decimal place? The following will return 33.00, but how can I get the result of 33.33?

select cast((100/3) as decimal(10,2)) as Result

Thank You.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-28 : 23:51:10
[code]
select 100.0 / 3

or multiply it with 1.0

select 100 * 1.0 / 3
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-29 : 02:29:56
Here is the reason
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nitookatyal
Starting Member

4 Posts

Posted - 2010-01-29 : 04:26:13
select cast(cast(100 as decimal)/3 as decimal(10,2)) as Result

Nitoo katyal
Software Engineer
Go to Top of Page
   

- Advertisement -