Home » C#.Net

float keyword in C#

C# float keyword: Here, we are going to learn about the float keyword in C#, what is float keyword, how to use it in C#?
Submitted by IncludeHelp, on March 07, 2019

C# float keyword

In C#, float is a keyword which is used to declare a variable that can store a floating point value between the range of ±1.5 x 10−45 to ±3.4 x 1038. float keyword is an alias of System.Single.

It occupies 4 bytes (32 bits) space in the memory.

Note: To represent a float value, we use a suffix f or F with the value.

Syntax:

    float variable_name = value;

C# code to demonstrate example of float keyword

Here, we are declaring a float variable num, initializing it with the value 12345.6789f and printing its value, type and size of a float type variable.

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //variable declaration
            float num = 12345.6789f;

            //printing value
            Console.WriteLine("num: " + num);
            //printing type of variable
            Console.WriteLine("Type of num: " + num.GetType());
            //printing size
            Console.WriteLine("Size of a float variable: " + sizeof(float));
            //printing minimum & maximum value of float
            Console.WriteLine("Min value of float: " + float.MinValue);
            Console.WriteLine("Max value of float: " + float.MaxValue);

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

Output

num: 12345.68
Type of num: System.Single
Size of a float variable: 4
Min value of float: -3.402823E+38
Max value of float: 3.402823E+38





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




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.