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

Author  Topic 

xpandre
Posting Yak Master

212 Posts

Posted - 2011-11-21 : 18:01:56
Hi Guys,

DECLARE @Float1 float, @Float2 float, @Float3 float, @Float4 float;

SET @Float1 = 64.99

SET @Float2 = 4.71

SET @Float3 = @Float1 + @Float2
select @Float3 as f3

SELECT @Float3 - @Float1 as f4



f3 = 69.7
f4 = 4.70999999999999
Why does float just mess up the scale to such an extend?

Another thing, I am using float datatype to store money in my application. I have few limitations from the front end where in they use double which doesnot accept decimal output. Do we have any known issues with using float as a storage datatype for curency?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-21 : 18:05:03
That's why you shouldn't use float data type where accuracy matters. Float is for approximate data.

Fix the front end so that you can use decimal or money data type.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-21 : 18:06:15
From Books Online about float/real:

quote:

Approximate-number data types for use with floating point numeric data. Floating point data is approximate; therefore, not all values in the data type range can be represented exactly.



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xpandre
Posting Yak Master

212 Posts

Posted - 2011-11-22 : 18:35:42
Hey Tara...Thank you..
We decided to change the datatype to either money or decimal.

Thanks again..
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-22 : 18:43:09
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -