Value was either too large or too small for a Decimal

后端 未结 2 1683
执笔经年
执笔经年 2021-02-18 20:05

I have the following piece of code:

double shortfall = GetSomeNumber(); //3.3588548831176006E+29

if (shortfall > 0)
{
  returnValue = Convert.ToDecimal(short         


        
2条回答
  •  旧巷少年郎
    2021-02-18 20:32

    It means that the value returned cannot be converted to decimal as it is too large.

    Decimal values can be between positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335 - see MSDN.

    Double can handle much larger numbers - negative 1.79769313486232e308 to positive 1.79769313486232e308. These will not all be convertible to Decimal.

提交回复
热议问题