Keywords are the words in a language that are used for some internal process or represent some predefined actions.
decimal is a keyword that is used to declare a variable that can store a floating type value from the range of ±1.0 x 10-28 to ±7.9228 x 1028. It is an alias of System.Decimal and occupies 16 bytes (128 bits) in the memory.
Syntax:
decimal variable_name = value;
We have to use ‘m’ or ‘M’ as a suffix with the literal, to represent a decimal value.
Example:
Input: 7271.6521M
Output: num: 7271.6521
Size of a decimal variable: 16
Input: -371.83436
Output: Type of num: System.Decimal
num: -371.83436
Size of a decimal variable: 16
Example 1:
// C# program for decimal keyword using System; using System.Text; class GFG { static void Main(string[] args) { // char variable declaration decimal num1 = 7271.6521M; // to print value Console.WriteLine("num: " + num1); // to print size of a decimal Console.WriteLine("Size of a decimal variable: " + sizeof(decimal)); } } |
Output:
num: 7271.6521 Size of a decimal variable: 16
Example 2:
// C# program for decimal keyword using System; using System.Text; namespace geeks { class GFG { static void Main(string[] args) { // char variable declaration decimal num1 = -371.83436m; // to print type of variable Console.WriteLine("Type of num: " + num1.GetType()); // to print value Console.WriteLine("num: " + num1); // to print size of a decimal Console.WriteLine("Size of a decimal variable: " + sizeof(decimal)); // hit ENTER to exit Console.ReadLine(); } } } |
Output:
Type of num: System.Decimal num: -371.83436 Size of a decimal variable: 16
Recommended Posts:
- How to implement is functionality without using is keyword in C#
- C# | this Keyword
- C# | finally keyword
- C# | as Operator Keyword
- C# | is Operator Keyword
- Is vs As operator keyword in C#
- Static keyword in C#
- typeof Operator Keyword in C#
- Invoking an overloaded constructor using this keyword in C#
- Difference between readonly and const keyword in C#
- LINQ | Let Keyword
- uint keyword in C#
- byte Keyword in C#
- char keyword in C#
- bool Keyword in C#
- sbyte Keyword in C#
- float keyword in C#
- double Keyword in C#
- void Keyword in C#
- short keyword in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

