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
2.3 is double. That is the language rules; any numeric literal with a decimal point in it is a double, unless it has a F suffix (float), or M suffix (decimal):
x = 2.3F; // fine
The compiler helpfully tells me this, too:
Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type