decimal
The C# number type that stores base-10 digits exactly, with 28 to 29 significant digits, which makes it the right type for money.
In more detail
Write decimal literals with an m suffix, such as 19.90m. Decimal keeps the scale you give it, so 19.90m * 3 prints 59.70, and 0.1m + 0.2m equals 0.3m exactly.
Example
decimal price = 19.90m;Related terms
- floating-point number — A number with a fractional part stored in binary, which can only approximate most decimal values.
- significand — The part of a floating-point or decimal number that holds its significant digits, as opposed to the exponent that places the decimal point.
- int — The C# type for 32-bit whole numbers from about minus 2.1 billion to 2.1 billion, used for counts, quantities and most identifiers.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Collections, Generics, and LINQ — Modern .NET Core, C# & Enterprise Microservices