What is a FLOAT? Floating Point Variables — Programming Theory

Definition of FLOAT

The name FLOAT comes from the "float­ing point" numer­i­cal rep­re­sen­ta­tion sys­tem and refers to a type of prim­i­tive vari­able that is char­ac­ter­ized by being a numer­i­cal vari­able that admits a dec­i­mal part, it can be used to rep­re­sent pos­i­tive and neg­a­tive real num­bers with­in a cer­tain range and with a cer­tain pre­ci­sion that depends on the type of float­ing point vari­able chosen.

Here is a more detailed arti­cle about what are vari­ables in pro­gram­ming and the dif­fer­ent types of vari­ables.

CHECK OUT THIS CRAZY EXPERIMENT

Types of FLOATING POINT variables and ranges

There are dif­fer­ent types of float­ing point vari­ables that we can use in pro­gram­ming, the best known of these vari­ables is the FLOAT itself, in which 32 bits are used to rep­re­sent the float­ing point val­ue, but there are oth­er types of float­ing point vari­ables as well, only with more or less bits for their rep­re­sen­ta­tion. In the fol­low­ing table you can see some of these variables.

Syntax of FLOATING POINT variables in Unity

To define a float­ing point vari­able, we use the key­word of the first col­umn fol­lowed by the name of the vari­able, for exam­ple as follows:

float aFloat;
dou­ble aDou­ble;
dec­i­mal aDecimal;

Cuan­do ingre­samos val­ores con dec­i­males se uti­liza el pun­to como sep­a­rador y en el caso par­tic­u­lar de las vari­ables tipo float, cuan­do se le asigna un val­or hay que hac­er­lo se suele incluir la letra "f", para explic­i­tar que el val­or que indicamos es de tipo float, por ejemplo:

When we enter val­ues with dec­i­mals we use the dot as a sep­a­ra­tor and in the par­tic­u­lar case of float type vari­ables, when we assign a val­ue we usu­al­ly include the let­ter "f", to make it explic­it that the val­ue we indi­cate is a float val­ue, for example:

aFloat = 3.51f

In the pre­vi­ous case, as we are assign­ing a dec­i­mal val­ue in a float vari­able, there would be no prob­lem in not includ­ing the "f", how­ev­er in oth­er oper­a­tions such as method exe­cu­tions pass­ing float val­ues as para­me­ters, it may be manda­to­ry to spec­i­fy that such val­ue is a float.

Applications of a FLOATING POINT variable in Unity

The float­ing point vari­ables allow us to rep­re­sent data that belong to the numer­i­cal set of real num­bers, so we can use it to rep­re­sent num­bers that have that nature, for exam­ple weight, tem­per­a­ture, vol­ume, height. They are also used to build more com­plex data struc­tures such as arrays and arrays of float data, pro­gram­ming class­es such as Vector2 and Vector3 or we can also define our own pro­gram­ming class­es and use floats in their inter­nal structure.

Scroll to Top