468,736 Members | 2,158 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,736 developers. It's quick & easy.

Converting float in C to C#

Hello there,
I am using a 3rd party library and a function which requires a float
value in one of its methods. My data is in a string format and i tried
using Convert.ToDouble and Convert.ToSingle, but didn't work either way.
The value of string is "-57475.4531". The help in VS .NET 2003 tells me
that these convert methods will return double and single precision float
point values respectively but i needed to also cast the return to the
float type to make the compiler happy. First how do i correctly convert
a string to a float? As a side note, it does not makes sense to expose
the poor programmer to float in C and C++ and then take that and hide it
without explaining it somewhere. So, to give the benefit of doubt, the
explanation must be somewhere i have not come across. Any help will be

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
1 1623
I tried float f = Convert.ToSingle("-57475.4531"); and it compiled
alright. I have also tried f.GetType().FullName and it displayed
System.Single. Tried same for the ToDouble and got System.Double as a
Can you please share the code snippet. It'll help to understand the

Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.