Good Day,
In order to work with decimal data types, I have to do this with variable initialization:
decimal aValue = 50.0M;
What does the M part stand for?
coson
Good Day,
In order to work with decimal data types, I have to do this with variable initialization:
decimal aValue = 50.0M;
What does the M part stand for?
coson
See this (written by our own Jon Skeet):
http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88466.aspx
and this (more detail):
http://www.blackwasp.co.uk/CSharpNumericLiterals.aspx
M means decimal. If you don't add it the number will be treated as a double. D is double.
It means it's a decimal literal, as others have said. However, the origins are probably not those suggested elsewhere in this answer. From the C# Annotated Standard (the ECMA version, not the MS version):
The
decimal
suffix is M/m since D/d was already taken bydouble
. Although it has been suggested that M stands for money, Peter Golde recalls that M was chosen simply as the next best letter indecimal
.
A similar annotation mentions that early versions of C# included "Y" and "S" for byte
and short
literals respectively. They were dropped on the grounds of note being useful very often.