Why there is not exist method Convert.ToFloat()
,C# has ToDouble()
,ToDecimal()
...
I want convert to float, which method can be used? (float)var?
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.
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)
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 :) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With