Why can't Double be implicitly cast to Decimal

后端 未结 3 710
青春惊慌失措
青春惊慌失措 2020-11-30 13:49

I don\'t understand the casting rules when it comes to decimal and double.

It is legal to do this

decimal dec = 10;
double doub = (double) dec;
         


        
3条回答
  •  生来不讨喜
    2020-11-30 14:04

    Decimal is more precise, so you would lose information. That's why you can only do it explicitely. It's to protect you from losing information. See MSDN

    http://msdn.microsoft.com/en-us/library/678hzkk9%28v=VS.100%29.aspx

    http://msdn.microsoft.com/en-us/library/364x0z75.aspx

提交回复
热议问题