Link to home
Start Free TrialLog in
Avatar of simondopickup
simondopickup

asked on

Convert a string to float

Experts is there a function out there that will convert a string with an exponential component into a float?

1.902922E+01 -- i need to extract this from a file and store at as a float variable...

I am struggling to find someway of doing this - note that the format of the string is always the same - 6 numbers after the decimal point, then the E, then power term..
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ooops, and there of course also is '_ecvt()' and friends (see http://docs.hp.com/en/B2355-60130/ecvt.3C.html), e.g.
#include <stdlib.h>
#include <stdio.h>
 
int main( void )
{
   int     decimal,   sign;
   char    *buffer;
   int     precision = 10;
   double  source = 3.1415926535;
 
   buffer = _ecvt( source, precision, &decimal, &sign ); // C4996
 
   printf( "source: %2.10f   buffer: '%s'  decimal: %d  sign: %d\n",
           source, buffer, decimal, sign );
}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial