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)
 Float Value

Author  Topic 

TMDOSS
Starting Member

33 Posts

Posted - 2009-11-20 : 14:04:03
I'm computing values from 4 int colums (the sum is 465)
if I divide the sum by 60 I should get 7.75, but i always get
7. Pl help

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-11-20 : 14:10:18
quick fix is to devide by 60.0

you need to make the denominator more precise

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-20 : 14:33:34
I give up

What 4 integers give you 465?




DECLARE @a int, @b int, @c int, @d int
SELECT @a = 9, @b = 3, @c = 4, @d = 5
SELECT @a*@b*@c*@d

SELECT 465/60.00




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-11-20 : 15:24:41
actually he said sum (not product) so:

DECLARE @a int, @b int, @c int, @d int
SELECT @a = 462, @b = 1, @c = 1, @d = 1
SELECT (@a+@b+@c+@d) / 60.0

but how about 465, 1, 1, 1

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-20 : 15:33:11
quote:
Originally posted by TG

actually he said sum (not product) so:

DECLARE @a int, @b int, @c int, @d int
SELECT @a = 462, @b = 1, @c = 1, @d = 1
SELECT (@a+@b+@c+@d) / 60.0

but how about 465, 1, 1, 1

Be One with the Optimizer
TG



Go get some crab cakes and have a Philips Bloody Mary

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-23 : 01:40:44
quote:
Originally posted by TMDOSS

I'm computing values from 4 int colums (the sum is 465)
if I divide the sum by 60 I should get 7.75, but i always get
7. Pl help



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
   

- Advertisement -