#include<stdio.h>
#include<string.h>
int main()
{
char s[100] ="4.0800" ;
printf("float value : %4.8f\n" ,(float) atoll(s));
return 0;
}
I expect the output should be 4.08000000 whereas I got only 4.00000000.
Is there any way to get the numbers after the dot?
Use
atof()orstrtof()* instead:https://cplusplus.com/reference/cstdlib/atof/
https://cplusplus.com/reference/cstdlib/strtof/
atoll()is meant for integers.atof()/strtof()is for floats.The reason why you only get
4.00withatoll()is because it stops parsing when it finds the first non-digit.*Note that
strtof()requires C99 or C++11.