float keyword in C#

Keywords are the words in a language that are used for some internal process or represent some predefined actions. float is a keyword that is used to declare a variable which can store a floating point value from the range of ±1.5 x 10-45 to ±3.4 x 1038. It is an alias of System.Single.

Syntax:

float variable_name = value;

float keyword occupies 4 bytes (32 bits) space in the memory. We use a suffix f or F with the value to represent a float value.

Example:

Input: -3629.4586F

Output: num: -3629.458
        Size of a float variable: 4

Input: 16345.6456f

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

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for float keyword
using System;
using System.Text;
  
class GFG {
  
    static void Main(string[] args)
    {
        // variable declaration
        float num = -3629.4586F;
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a float variable: " + sizeof(float));
    }
}

chevron_right


Output:

num: -3629.458
Size of a float variable: 4

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for float keyword
using System;
using System.Text;
  
namespace geeks {
  
class GFG {
  
    static void Main(string[] args)
    {
        // variable declaration
        float num = 16345.6456f;
  
        // to print type of variable
        Console.WriteLine("Type of num: " + num.GetType());
  
        // to print value
        Console.WriteLine("num: " + num);
  
        // to print size
        Console.WriteLine("Size of a float variable: " + sizeof(float));
  
        // to print minimum & maximum value of float
        Console.WriteLine("Min value of float: " + float.MinValue);
        Console.WriteLine("Max value of float: " + float.MaxValue);
    }
}
}

chevron_right


Output:

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



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.