Sql Server float and System.Double decimal points

Posts   
 
    
AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 03-Dec-2013 17:54:32   

Hello, I'm using v3.1 build March 12th, 2012, .NET 4.0 and SQL Server 2008 R2.

I generated action stored procedure in the designer and the stored procedure has parameters of type float. Code generator created a proc wrapper with .NET parameter types System.Double. That's good.

When running SQL profiler, I've noticed that even though my values in .NET code only have 2 decimals, the proc is being called with lots of decimals.

For example, when value in .NET is 591215.52, the proc is getting called with 591215.52000000002

Do you know why this may be happening?

Thanks. Albert

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 03-Dec-2013 20:39:59   

Could it be because they are floats and 591215.52 when stored becomes 591215.520000000002?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Dec-2013 06:39:42   

SQL float, is an approximate data type. If you want to limit the number to a specific decimal points, then I'd suggest using SQL decimal(x, y) dataType.

ref http://stackoverflow.com/questions/1209181/what-represents-a-double-in-sql-server