i am new in c programming.i want to tell me
how can i convert the decimal part of an float number in integer .for instance in the float number 1845.32
i want the integer variable decimal to have the value 32.
main()
{
float f1 = 1845.32;
int r1 = 0;
char *p, sf1[20];
sprintf(sf1, "%6.2f", f1); /* convert float to string */
printf("SF1 = %s\n", sf1);
p = strchr(sf1, '.'); /* find the decimal point */
p++; /* point to the first char after the decimal point */
printf("P = %s\n", p);
r1 = atoi(p); /* convert string to int */
printf("R1 = %d\n", r1);
return;
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.