Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no Convert.toFloat() method?

Tags:

c#

Why there is not exist method Convert.ToFloat(),C# has ToDouble(),ToDecimal()...
I want convert to float, which method can be used? (float)var?

like image 462
SleeplessKnight Avatar asked Aug 30 '11 03:08

SleeplessKnight


People also ask

How to Convert a String into Float c#?

Use the ToDouble() Method to Convert a String to Float in C# In C#, we can also use the ToDouble() method to convert a string to a float value.

What is ToSingle in C#?

ToSingle(Object) Converts the value of the specified object to a single-precision floating-point number. ToSingle(Int32) Converts the value of the specified 32-bit signed integer to an equivalent single-precision floating-point number. ToSingle(Int16)


1 Answers

There is - but it's called Convert.ToSingle(). float is a C# alias for the System.Single type.

"Single" is the name for a float in the BCL. "float" is an alias provided by C#. There's a Convert.ToSingle() method, just like there's Convert.ToInt32() instead of Convert.ToInt().

See this thread Convert class

(BTW - I didn't know this either, so I learned something new today :) )

like image 118
Tim Avatar answered Nov 12 '22 21:11

Tim