What is a FLOAT? Floating Point Variables – Programming Theory

Definition of FLOAT

The name FLOAT comes from the “floating point” numerical representation system and refers to a type of primitive variable that is characterized by being a numerical variable that admits a decimal part, it can be used to represent positive and negative real numbers within a certain range and with a certain precision that depends on the type of floating point variable chosen.

Here is a more detailed article about what are variables in programming and the different types of variables.

A SHORT BREAK WITH THE LATEST NEWS

CONSIDER SUBSCRIBING!


LET'S CONTINUE WITH THE ARTICLE

Types of FLOATING POINT variables and ranges

There are different types of floating point variables that we can use in programming, the best known of these variables is the FLOAT itself, in which 32 bits are used to represent the floating point value, but there are other types of floating point variables as well, only with more or less bits for their representation. In the following table you can see some of these variables.

Type of variableNumber of BitsPrecisionSmallest representable valueLargest representable value
float32~6 a 9 digits±1.5 x 10−45±3.4 x 1038
double64~15 a 17 digits±5.0 × 10−324±1.7 × 10308
decimal128~28 a 29 digits±1.0 x 10-28±7.9 x 1028
Comparative table of the different types of floating point variables in C# with number of bits and approximate range of representation

Syntax of FLOATING POINT variables in Unity

To define a floating point variable, we use the keyword of the first column followed by the name of the variable, for example as follows:

float aFloat;
double aDouble;
decimal aDecimal;

Cuando ingresamos valores con decimales se utiliza el punto como separador y en el caso particular de las variables tipo float, cuando se le asigna un valor hay que hacerlo se suele incluir la letra “f”, para explicitar que el valor que indicamos es de tipo float, por ejemplo:

When we enter values with decimals we use the dot as a separator and in the particular case of float type variables, when we assign a value we usually include the letter “f”, to make it explicit that the value we indicate is a float value, for example:

aFloat = 3.51f

In the previous case, as we are assigning a decimal value in a float variable, there would be no problem in not including the “f”, however in other operations such as method executions passing float values as parameters, it may be mandatory to specify that such value is a float.

Applications of a FLOATING POINT variable in Unity

The floating point variables allow us to represent data that belong to the numerical set of real numbers, so we can use it to represent numbers that have that nature, for example weight, temperature, volume, height. They are also used to build more complex data structures such as arrays and arrays of float data, programming classes such as Vector2 and Vector3 or we can also define our own programming classes and use floats in their internal structure.

Secured By miniOrange