Reputation: 31
I tried to understand why it seems not to be possible to exactly set a precision for a float / double value.
However .NET allows me to use Math.Round on such values an the inspector Shows me exactly what I rounded and / or entered.
Whenever I try to save such a value back to a table I get a Statement containing 86,609001159668 instead of 86,609
There seems so be now way in which the entered value reaches the table correctly.
I could change anything in my code to achieve this Goal but not the columntype itself.
Any ideas?
Thanks,
Chris
Upvotes: 3
Views: 2694
Reputation: 63772
.NET floats aren't decimal-precise. The only BCL decimal type that is decimal-precise is decimal
. float
and double
are binary "decimals", so there's no way to represent 86.609
precisely in them. Using Math.Round
simply brings the value close enough to 86.609
that it's printed out as such during the rounding happening as part of ToString
.
So if you want precise decimal-point decimals, use decimal
in .NET.
Upvotes: 4