Web Hosting Talk







View Full Version : Simple C str to float conversion


andretenreiro
03-25-2010, 08:45 AM
#include <stdio.h>

int main()
{

char *str = "-0.096686035";
double value;

value = atof(str);

printf("The value is: %.10f \n", value);


}


The value is: -1.0000000000


How can I get the exactly value instead of the rounded value?

RemyHorton
03-25-2010, 10:46 AM
You need to include stdlib.h as well..

andretenreiro
03-25-2010, 10:49 AM
You need to include stdlib.h as well..

It worked!

Thanks :-)

How come the did not gave any error?