What is Convert.ToSingle for? [closed]

-5

I am reviewing an algorithm already created, 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));
    
asked by jorge 31.08.2017 в 15:17
source

4 answers

0

Converts a data type string , int16 , int32 , int64 , float , double , char , bool , Datetime to single type Single.

It is good to note that Single and float are the same, there is no difference between the two.

Single s = 11;
float f = 22;
s = f; // valido
f = s; // valido

Single was a data type introduced by microsoft while float was left for programmers to migrate from make the transition easier for the float data type in c . Let's say that the type float is an alias for Single .

    
answered by 31.08.2017 / 15:30
source
1

Converts the value of the specified decimal number to a simple precision float number, that is, very large numbers will show them in a simple type:

Example:

result = Convert.ToSingle(Decimal.MinValue);

//El valor de Decimal.MinValue = '-79228162514264337593543950335'
//El resultado 'result' de esta operación és: '-7.922816E+28'

Page with examples

    
answered by 31.08.2017 в 15:30
1

Class Convert ( Reference ) provides methods to convert data.

According to the comments in its source code , conversions can be made from according to this table:

// From:  To: Bol Chr SBy Byt I16 U16 I32 U32 I64 U64 Sgl Dbl Dec Dat Str
// ----------------------------------------------------------------------
// Boolean     x       x   x   x   x   x   x   x   x   x   x   x       x
// Char            x   x   x   x   x   x   x   x   x                   x
// SByte       x   x   x   x   x   x   x   x   x   x   x   x   x       x
// Byte        x   x   x   x   x   x   x   x   x   x   x   x   x       x
// Int16       x   x   x   x   x   x   x   x   x   x   x   x   x       x
// UInt16      x   x   x   x   x   x   x   x   x   x   x   x   x       x
// Int32       x   x   x   x   x   x   x   x   x   x   x   x   x       x
// UInt32      x   x   x   x   x   x   x   x   x   x   x   x   x       x
// Int64       x   x   x   x   x   x   x   x   x   x   x   x   x       x
// UInt64      x   x   x   x   x   x   x   x   x   x   x   x   x       x
// Single      x       x   x   x   x   x   x   x   x   x   x   x       x
// Double      x       x   x   x   x   x   x   x   x   x   x   x       x
// Decimal     x       x   x   x   x   x   x   x   x   x   x   x       x
// DateTime                                                        x   x
// String      x   x   x   x   x   x   x   x   x   x   x   x   x   x   x
// ----------------------------------------------------------------------

On the other hand, type Single ( Reference ) in C # is what in other languages such as Java is interpreted as float : a precision floating point number.

Therefore Convert.ToSingle is a method that converts data of types bool , SByte , byte , int (and variations), double , decimal and string to data type Single or "float".

    
answered by 31.08.2017 в 15:27
0

The ToSingle method attempts to convert the value passed as a parameter to a Simple Precision Floating Number ie 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 floating:

Approximately 5.0 × 10 ^ 324 to 1.7 × 10 ^ 308 with precision of 15-16 digits.

The standard that governs these types is that of IEEE 754 formats

More information: link

    
answered by 31.08.2017 в 15:34