Converting float in C to C#

M

Meya-awe

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
appreciated.
thanks,
BRAMOIN
 
M

Maqsood Ahmed

Hello,
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
result.
Can you please share the code snippet. It'll help to understand the
problem.

Cheers.
Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies
http://www.kolachi.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top