decimal keyword in C#

C# decimal keyword: Here, we will find out about the decimal keyword in C#, what is the decimal keyword, how to utilize it in C#?

C# decimal keyword

In C#, the decimal is a keyword which is utilized to announce a variable that can store a drifting sort (esteem with the exactness) between the scope of ±1.0 x 10-28 to ±7.9228 x 1028. the decimal keyword is a nom de plume of System.Decimal.

It possesses 16 bytes (128 bits) in the memory.

Note: To speak to a decimal worth, we use m or M as a postfix with the exacting.

Syntax:

    decimal variable_name = value;

It can store the incentive between the scope of ±1.0 x 10-28 to ±7.9228 x 1028.

C# code to show an example of decimal keyword:

Here, we are announcing a decimal variable num, introducing it with the worth 5610.2361m and printing its worth, type and size of a decimal kind variable.

using System;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            //char variable declaration
            decimal num = 5610.2361m;

            //printing value
            Console.WriteLine("num: " + num);
            //printing type of variable
            Console.WriteLine("Type of num: " + num.GetType());
            //printing size of a decimal 
            Console.WriteLine("Size of a decimal variable: " + sizeof(decimal));

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output:

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

Leave a Comment

error: Alert: Content is protected!!