If I try and convert Decimal.MaxValue
from Decimal
to Single
and back again, the conversion fails with an OverflowException
:
Convert.ToDecimal(Convert.ToSingle(Decimal.MaxValue))
// '...' threw an exception of type 'System.OverflowException'
// base: {"Value was either too large or too small for a Decimal."}
What gives? Surely the value of Decimal.MaxValue
as a Single
should be a valid Decimal
value?
I understand that the differences between Single
and Decimal
and expect a loss of precision converting from Decimal
to Single
but as Single.MaxValue
is greater than Decimal.MaxValue
it doesn't make sense that the "Value was either too large or too small for Decimal". If you think that does make sense please explain why in an answer.
Additionally,
Convert.ToSingle(Decimal.MaxValue)
// 7.92281625E+28
so there is no problem converting this number to a Single
.