By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,941 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Converting float in C to C#

P: n/a
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 ***
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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 -
Kolachi Advanced Technologies

*** Sent via Developersdex ***
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.