Declaration suffix for decimal type
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In C#, the suffix for a decimal literal is m or M. That small suffix matters because numeric literals with a fractional part default to double, not decimal. If you want the precision and behavior of decimal, especially for money and exact base-10 values, you need to mark the literal explicitly.
Why the Suffix Exists
Different numeric types represent numbers differently. In C#:
- '
intis for whole numbers' - '
doubleis the default floating-point type for decimal-looking literals' - '
decimalis a higher-precision base-10 type designed for financial and exact decimal work'
So this code creates a double:
To create a decimal, add the suffix:
Without the suffix, the compiler treats the literal as the wrong numeric type for many decimal assignments and expressions.
Basic Decimal Literal Examples
Both lowercase and uppercase suffixes are valid.
All four literals are decimal values.
What Happens Without the Suffix
If you try to assign a decimal-looking literal directly to a decimal variable without the suffix, the compiler rejects it.
That happens because 19.99 is parsed as a double literal, and C# does not perform that conversion implicitly in this case.
Why decimal Is Used for Money
double is a binary floating-point type. Many decimal values cannot be represented exactly in binary floating-point, which can create tiny rounding artifacts.
This is why financial code often uses decimal. The suffix is not cosmetic. It is the point where you tell the compiler which arithmetic model you actually want.
Expressions Must Stay in the Decimal World
Even if one variable is decimal, mixed-type expressions can still cause problems if the literals are not suffixed.
If you accidentally write 0.075 without the suffix, the expression stops being consistent and the compiler may complain or force you into explicit casts.
Common Places the Suffix Is Needed
You usually need m in:
- hard-coded prices
- percentage rates
- financial calculations
- tests that compare exact decimal values
For example:
Every literal that should participate as a decimal is marked clearly.
Do Not Add the Suffix Blindly
Use decimal when exact decimal arithmetic is what the domain requires. Do not use it automatically for every numeric value. Scientific and graphics calculations often use double because range and performance characteristics differ.
The important point is to choose intentionally:
- '
decimalfor money and base-10 precision needs' - '
doublefor general floating-point work where binary floating-point is acceptable'
Once you choose decimal, the suffix keeps literals aligned with that choice.
Common Pitfalls
The most common mistake is forgetting the m suffix and then wondering why a decimal assignment fails to compile. Another is mixing decimal variables with unsuffixed double literals in expressions, which creates awkward conversion issues. Teams also sometimes choose decimal for every numeric problem even when they do not need its precision model. Finally, developers sometimes assume the suffix changes output formatting, when it actually changes the literal's type and arithmetic behavior.
Summary
- In C#, the decimal literal suffix is
morM. - Decimal-looking literals default to
doubleunless you add the suffix. - Use
decimalfor money and exact base-10 calculations. - Keep expressions consistent by suffixing decimal literals throughout the formula.
- The suffix is about type correctness, not just syntax style.

