Sql Server decimal to .NET float (single)

Posts   
 
    
aspicer
User
Posts: 65
Joined: 14-Nov-2008
# Posted on: 31-Jan-2011 19:28:32   

**Version **3.0 Build: January 3rd, 2011 DB: SQL Server 2008

I have a field in a table called "BestScore" which is used to represent the highest score achieved on an activity (max 100). The database type for the column is decimal(5,2) so that I can represent scores with a two digit scale like "[i]76.34[/i]". It seems that the designer should default this column to single (float) instead of decimal or at least let me change it.

When I change the datatype to single I get a validation error in the designer stating that I need to specify a type converter because the fields don't match. Shouldn't I be able to change this type without a type converter given that my precision for this column is 5 (.NET single precision is 7)?

Thanks, Adam

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Feb-2011 05:47:10   

As a matter of fact it should be mapped as decimal (you can confirm that on msnd ado.net docs). What do you want it mapped as float? If you need a different .net type, you should implement your own typeconverter which is no difficult, but you can incurring in overflows or truncated values.

David Elizondo | LLBLGen Support Team
aspicer
User
Posts: 65
Joined: 14-Nov-2008
# Posted on: 01-Feb-2011 15:10:55   

daelmo wrote:

As a matter of fact it should be mapped as decimal (you can confirm that on msnd ado.net docs).

Thanks, I found the docs here: http://msdn.microsoft.com/en-us/library/cc716729.aspx

What do you want it mapped as float?

I am using those fields for simple percentages that will have a precision of 5 with a 2 digit scale (so I can represent ###.##). In that case, perhaps a Decimal is overkill and I should instead use a Real in SQL Server?

To me it seemed that since I was working with such a small Decimal (with precision = 5), I thought that I would be able to select a different compatible .NET type such as a Single. I see now that if I keep with the Decimal type that I'll have to provide a typeconverter.

I'll have to do some testing in using a Real instead of a Decimal within SQL Server. Do you have any thoughts on the datatype given what I mentioned above I would be storing?

Thanks,

aspicer
User
Posts: 65
Joined: 14-Nov-2008
# Posted on: 01-Feb-2011 16:40:47   

After further investigation, I will want to stick with using the decimal in .NET. Thanks for your time.