Code://code to convert string(containing digits) to equivalent float value //Its giving approx value but not exact value #include<stdio.h> #include<ctype.h> #include<math.h> int main() { char a[20]; int c,i=0,k,sign=1; float f=0; while((c=getchar())!='\n' && i<19) { a[i]=c; i++; } a[i]='\0'; for(i=0;a[i]==' ' && i<19;i++) ; if( (a[i]=='+' && (sign=1)) || (a[i]=='-' && (sign=-1)) ) i++; for(;a[i]!='\0'&&a[i]!='.';i++) { f=f*10+(a[i]-'0'); } if(a[i]=='.') for(k=-1,i++;a[i]!='\0';i++,k--) f=f+pow(10,k)*(a[i]-'0'); f*=sign; printf("\n num is %f",f); return 0; } o/p: 123.654 num is 123.653999