Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to use atof() to convert a string to floating point in C

1 Answer

0 votes
#include <stdlib.h>
#include <stdio.h>
 
int main(void)
{
    printf("atof(\"  -0.0000978XYZ\") = %g\n", atof("  -0.0000978XYZ"));
    printf("atof(\"0.01314\") = %g\n", atof("0.01314"));
    printf("atof(\"11e15\") = %g\n", atof("11e15"));
    printf("atof(\"-0x1a\") = %g\n", atof("-0x1a"));
    printf("atof(\"inF\") = %g\n", atof("inF"));
    printf("atof(\"Nan\") = %g\n", atof("Nan"));

    return 0;
}
  
/*
run:
 
atof("  -0.0000978XYZ") = -9.78e-005
atof("0.01314") = 0.01314
atof("11e15") = 1.1e+016
atof("-0x1a") = -0
atof("inF") = 0
atof("Nan") = 0

*/

 



answered Aug 25, 2016 by avibootz
edited Aug 26, 2016 by avibootz
...