Converting text in exponential form to double

M

Michael McGarry

Hi,

I have the text "5.21e-09" and I want to convert it to a double. atof()
does not seem to work, does anyone know how to convert it?

Michael
 
M

Michael McGarry

I figured this out myself. Strangely enough when I included stdlib.h
the problem was fixed.

I wonder what atof() function it was using without including this file?

Michael
 
R

red floyd

Michael said:
I figured this out myself. Strangely enough when I included stdlib.h
the problem was fixed.

I wonder what atof() function it was using without including this file?

Michael

Sounds like you're using C rather than C++. In that case, atof() would
be an implicit int function.
 
J

Jack Klein

I figured this out myself. Strangely enough when I included stdlib.h
the problem was fixed.

I wonder what atof() function it was using without including this file?

Michael

DON'T use atof(), or other ato... functions. They are dangerous. They
produce undefined behavior if the converted value is outside the range
of the destination type. Also you can never tell if a value of 0 is
the result of an actual representation of 0 in the character string,
or because the string was not convertible.

If you are using stdlib.h functions, use the strto... series. They
have defined behavior for all inputs other than a null pointer, and
offer facilities for error checking.
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top