Open In App

decimal keyword in C#

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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


Last Updated : 22 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads