Skip to content
Related Articles

Related Articles

float keyword in C#
  • Last Updated : 22 Jun, 2020

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:






// 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));
    }
}

Output:

num: -3629.458
Size of a float variable: 4

Example 2:




// 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);
    }
}
}

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
Recommended Articles
Page :