I have a FLOAT(126) column that was mapped to a Decimal by the Entity Framework. It works both for writing and reading, except in one case.
When I write a high precision value such as:
1m / 3m = 0.33333333333333333333333333333333
I can’t read it, the framework throws an ArithmeticOverflowException.
How to solve that? My temporary solution is to round the number to 6 decimal places before inserting them. But what if I required the full precision?
Decimal only support 28-29 significant digits ( http://msdn.microsoft.com/en-us/library/364x0z75.aspx ) and since EF doesn’t support custom type mapping like NHibernate does – it’s not possible to load more than the type can handle.
I don’t know if it occurs to you but by converting a decimal to float you are losing precision and as you can see you end up with the quirky rounding that floats have. You really should be using decimal instead of float if you are after precision and also set the max significant digits to the max of decimal.