decimal
The decimal
keyword indicates a 128-bit data type. Compared to floating-point types, the decimal
type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations. The approximate range and precision for the decimal
type are shown in the following table.
Type |
Approximate Range |
Precision |
.NET Framework type |
decimal |
(-7.9 x 1028 to 7.9 x 1028) / (100 to 28) |
If you want a numeric real literal to be treated as decimal, use the suffix m or M, for example:
decimal myMoney = 300.5m;
Without the suffix m, the number is treated as a double and generates a compiler error.