Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the M stand for in C# Decimal literal notation?

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?

like image 270
coson Avatar asked Jun 10 '09 18:06

coson


People also ask

What is %M in printf?

The '%m' conversion is a GNU C Library extension. So: printf("%m\n", d); is equivalent to printf("%s\n", strerror (errno), d); which is equivalent to. printf("%s\n", strerror (errno));

What does =! Mean in C?

It could be a mistyping of the != operator, meaning not equal to. Example: if (a != b) { // a is not equal to b } It could be a mistyping a == ! b , meaning a is equal to not b , which would most commonly be used with booleans.

What does %C do in C?

%d is used to print decimal(integer) number ,while %c is used to print character . If you try to print a character with %d format the computer will print the ASCII code of the character.


2 Answers

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 by double. Although it has been suggested that M stands for money, Peter Golde recalls that M was chosen simply as the next best letter in decimal.

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 not being useful very often.

like image 161
Jon Skeet Avatar answered Sep 30 '22 22:09

Jon Skeet


From C# specifications:

var f = 0f; // float var d = 0d; // double var m = 0m; // decimal (money) var u = 0u; // unsigned int var l = 0l; // long var ul = 0ul; // unsigned long 

Note that you can use an uppercase or lowercase notation.

like image 24
Shadi Namrouti Avatar answered Sep 30 '22 21:09

Shadi Namrouti