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)
 Decimal Places Question

Author  Topic 

caisys
Starting Member

16 Posts

Posted - 2007-12-24 : 10:48:08
declare @d dec(9,2)
select @d = 55/3
select @d as result

result
------
18.00


How do i get:

result
-----
18.33


harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-24 : 10:54:21
quote:
Originally posted by caisys

declare @d dec(9,2)
select @d = 55/3.0
select @d as result

result
------
18.00


How do i get:

result
-----
18.33






Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-24 : 13:09:29
SQL Server will always implicitly convert result to data type of operands. thats why it strips of decimal part and returns integer result. Making denominator as decimal will implicitly cast the result as decimal.
the below link gives an idea on implicit concversions on sql:-

[url]http://msdn2.microsoft.com/en-us/library/aa226054(SQL.80).aspx[/url]
Go to Top of Page

caisys
Starting Member

16 Posts

Posted - 2007-12-24 : 16:48:57
Thank you both :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-26 : 01:11:50
and if you use variables then multiply it by 1.0

select @var1*1.0/@var2

Madhivanan

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

- Advertisement -