views:

49

answers:

2

I have 2 fields and I need these to be a floating decimal point. I wonder what data type to use while I'm designing bottom-up Linq-to-SQL classes.

EG: one value is 1.427600, another value is 1765.030, both would be in the same property/column.

+5  A: 

Use System.Decimal, if you require the accuracy.

Decimal will represent both your example values accurately.

driis
I guess i will continue with Decimal.
A: 

Why not a float or decimal type?

Randy Minder
Only use float if accuracy isn't critical; floats and doubles are both inaccurate after a certain place, whereas decimal is fully accurate. See @driis' answer.
John Rudy
In floating point numbering systems there are values that cannot be represented exactly, and sometimes those values are very common. For example, in IEEE floats the number 1/10 (0.10) is such a value - it's an infinitely repeating fraction. Now, language complers know how to generate the floating point value that is "closest" to what you asked for, but because the number you get isn't exactly what you had in mind inaccuracies start to creep in. If you perform some calculations those inaccuracies get magnified, so in general you shouldn't use floating point for monetary numbers.
Bob Jarvis