C# double to decimal precision loss?

138630.78380386264 is not exactly representable to double precision. The closest double precision number (as found here ) is 138630.783803862635977566242218017578125 which agrees with your findings.

138630.78380386264 is not exactly representable to double precision. The closest double precision number (as found here) is 138630.783803862635977566242218017578125, which agrees with your findings. You ask why the conversion to decimal does not contain more precision.

The documentation for Convert.ToDecimal() has the answer: The Decimal value returned by this method contains a maximum of 15 significant digits. If the value parameter contains more than 15 significant digits, it is rounded using rounding to nearest. The following example illustrates how the Convert.

ToDecimal(Double) method uses rounding to nearest to return a Decimal value with 15 significant digits. The double value, rounded to nearest at 15 significant figures is 138630.783803863, exactly as you show above.

– GreyCloud Sep 17 at 9:58 ok thanks for explaining that. Is there anyway to get the ToString to print out more than 15 sig fig? - I'd like to be able to get back to the original string - that way I could get Double to parse the string and do the conversion without loosing precision – GreyCloud Sep 17 at 10:12 doub.

ToString("G17") will give you the same string that the debugger produces. But I don't know for sure that's what the debugger is doing. Since double has limited precision you won't in general be able to parse the string and then get the original string back.

If you need to know the original string, remember it. – David Heffernan Sep 17 at 10:14 Thanks, I'll try "G17" - problem is the double is being produced via com interop so I cant get a string for it :( – GreyCloud Sep 17 at 10:18 1 @GreyCloud because Double only has a bit more than 15 decimal digits of precision. Everything after that is artifacts of the binary fraction format.

The method assumes that you're only interested in the "real" precision, not the accidental one. – Michael Borgwardt Sep 17 at 10:24.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions