I am reviewing an already created algorithm, to understand how to make a function that returns the average of three notes, but I would like to know what it does with the conver.tosingle
promedio = Convert.ToSingle((nota1 * 0.35) + (nota2 * 0.35) + (nota3 * 0.30));
The class
Convert
( Reference ) provides methods to convert data.According to the comments in your source code , the conversions can be done according to this table:
On the other hand, the type
Single
( Reference ) in C# is what is interpreted as in other languages like Javafloat
: a precision floating point number.Therefore it
Convert.ToSingle
is a method that converts data from typesbool
,SByte
,byte
,int
(and variations),double
,decimal
andstring
to the data typeSingle
or "float".Convert the value of the specified decimal number to a single precision float number, that is, very large numbers will be shown in a simple type:
Example:
Page with examples.
Converts a data type
string
,int16
,int32
,int64
,float
,double
,char
,bool
,Datetime
to type single Single.It is good to note that
Single
andfloat
are the same, there is no difference between the two.Single
was a data type introduced by microsoft while it was left to make it easier forfloat
programmers migrating from cc
to transition to the float data type in . Let's say the typefloat
is an alias forSingle
.The ToSingle method attempts to convert the value passed as a parameter to a single-precision Floating Number, i.e. a number in this range:
1.5 × 10^45 to 3.4 × 10^38 with a precision of 7 digits
If you used ToDouble it would be a double precision float:
Approximately 5.0 × 10^324 to 1.7 × 10^308 with precision of 15-16 digits.
The standard that governs these types is the IEEE 754 format.
More information: https://es.wikipedia.org/wiki/IEEE_coma_flotante