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
 General SQL Server Forums
 New to SQL Server Programming
 Decimal vs. float

Author  Topic 

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-04-29 : 11:43:55
Hi again, I'm having a little trouble understanding the difference between a decimal and a float. From what I understand, floats are rounded, so does that mean decimals are truncated?

If I'm calculating medians of integers less than 1000, which should I use? I'm thinking float since it takes up less storage, and also since the medians will always be integers or have only a .5 decimal place (so I shouldn't have to worry about the rounding, right?). Am I on the right track here?

Thank you!

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-29 : 11:53:48
floats are approximate values whereas decimals are accurate.
In your cse I would go for a decimal.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-29 : 11:54:45
You could go with either and probably wouldn't make much of a difference in practical terms. But, I would probably pick decimal - it would be precise. Use decimal (5,1) - that is 5 digits all together, with one reserved for decimal part.

As for storage, you would use up 5 bytes for decimal and 4 for float.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-29 : 11:55:53

I seem to be getting shot at a lot today!! I am not going to post anything more today, I promise!!
Go to Top of Page

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-04-29 : 12:11:42
Yeah, I figured there wasn't a dramatic difference. Thanks.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-04-29 : 12:47:32
well how many rows of data are you talking about,,,unless it's hundreds om millions or more, it's not an issue

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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -