C# float keyword: Here, we will find out about the float keyword in C#, what is float keyword, how to utilize it in C#?
C# float keyword:
In C#, the float is a keyword which is utilized to pronounce a variable that can store a floating-point an incentive between the scope of ±1.5 x 10−45 to ±3.4 x 1038. float keyword is an assumed name of System.Single.
It possesses 4 bytes (32 bits) space in the memory.
Note: To speak to float esteem, we utilize a postfix for F with the worth.
Syntax:
float variable_name = value;
C# code to show example of float keyword:
Here, we are announcing a float variable num, instating it with the worth 12345.6789f and printing its worth, 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