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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.