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:
using System;
using System.Text;
class GFG {
static void Main( string [] args)
{
float num = -3629.4586F;
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a float variable: " + sizeof ( float ));
}
}
|
Output:
num: -3629.458
Size of a float variable: 4
Example 2:
using System;
using System.Text;
namespace geeks {
class GFG {
static void Main( string [] args)
{
float num = 16345.6456f;
Console.WriteLine( "Type of num: " + num.GetType());
Console.WriteLine( "num: " + num);
Console.WriteLine( "Size of a float variable: " + sizeof ( 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
Last Updated :
22 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...