Home »
C#.Net
decimal keyword in C#
C# decimal keyword: Here, we are going to learn about the decimal keyword in C#, what is decimal keyword, how to use it in C#?
Submitted by IncludeHelp, on March 06, 2019
C# decimal keyword
In C#, decimal is a keyword which is used to declare a variable that can store a floating type value (value with the precision) between the range of ±1.0 x 10-28 to ±7.9228 x 1028. decimal keyword is an alias of System.Decimal.
It occupies 16 bytes (128 bits) in the memory.
Note: To represent a decimal value, we use m or M as a suffix with the literal.
Syntax:
decimal variable_name = value;
It can store the value between the range of ±1.0 x 10-28 to ±7.9228 x 1028.
C# code to demonstrate example of decimal keyword
Here, we are declaring a decimal variable num, initializing it with the value 5610.2361m and printing its value, type and size of a decimal type 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