Why the compiler decide 2.3 is double and not decimal?

后端 未结 4 950
庸人自扰
庸人自扰 2020-12-30 05:44

Why does the compiler decide that 2.3 is double so this code won\'t compile:

decimal x;
x = 2.3; // Compilation error - can not convert double to decimal.
x          


        
4条回答
  •  臣服心动
    2020-12-30 06:11

    Because Floatingpint numbers are always a little bit diffucult in calculation and in Valuerange, they are in Immediate notation always the biggest possible type. (in your case: Double).

    Non-Floating Points have some kind of the same Handling below, so they can be converted without any problem. If your value exceeds the Value-Range of a variable, it may cause an error (for example 257 for a Byte).

提交回复
热议问题