decimal keyword in C#

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

num: 7271.6521
Size of a decimal variable: 16

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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();
    }
}
}

chevron_right


Output:

Type of num: System.Decimal
num: -371.83436
Size of a decimal variable: 16



My Personal Notes arrow_drop_up


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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.