28

Possible Duplicate:
Declaration suffix for decimal type

Hey everyone,

In the following snippet of code; RewardValue is a decimal:

dto.RewardValue = 1.5;

Now, this gives me the following error:

"Cannot convert source type double to target type decimal"

Makes sense, and is easily fixable by changing that line of code to this:

dto.RewardValue = 1.5m;

Now, the "m" converts that to a decimal and all is good.

Does anybody know of somewhere where I could find a list of all those "m" type operators? (and if you could let me know what the proper term for those are, it would be greatly appreciated)

EDIT: Thanks to HCL and MartyIX for letting me know that these are referred to as "suffixes"

Community
  • 1
  • 1
Jim B
  • 8,036
  • 10
  • 48
  • 77
  • 2
    The answer to this is found at the "dupe" question, but the question asked there is much more targeted. It asks explicitly just for the decimal suffix (`decimal m = 2m;`), and this asks for a list of all "numeric suffixes". Fwiw, 2¢, etc. – ruffin Sep 30 '16 at 13:26

4 Answers4

29

I believe the term you're looking for is "suffix".

Examples:

1;    // int
1.0;  // double
1.0f; // float
1.0m; // decimal
1u;   // uint
1L;   // long
1UL;  // ulong
Adam Robinson
  • 177,794
  • 32
  • 275
  • 339
19

It's a pretty small list, really.

F:  float
D:  double
U:  uint
L:  long
UL: ulong
M:  decimal

Of course a plain integral value by itself is interpreted as an int, unless it's too big to be an int in which case it's a long, unless it's too big for a long in which case it's a ulong. If it's too big for a ulong, you can't use it as a literal (as far as I know).

A value with a decimal point in it is automatically interpreted (as you found out for yourself) as a double.

Dan Tao
  • 122,418
  • 53
  • 286
  • 437
3

http://dotnetperls.com/suffix-examples - they call it simply numeric suffixes (http://msdn.microsoft.com/en-us/library/b1e65aza(VS.71).aspx - also suffix here)

Suffix type: unsigned int

Character: U

Example: uint x = 100U;

Suffix type: long

Character: L

Example: long x = 100L;

Suffix type: unsigned long

Character: UL

Example: ulong x = 100UL;

Suffix type: float

Character: F

Example: float x = 100F;

Suffix type: double

Character: D

Example: double x = 100D;

Suffix type: decimal

Character: M

Example: decimal x = 100M;

Community
  • 1
  • 1
MartyIX
  • 26,515
  • 27
  • 129
  • 197
2

I believe it's called a "numeric litteral": http://www.blackwasp.co.uk/CSharpNumericLiterals.aspx

cirons42
  • 74
  • 1
  • 3