Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- integer_and_decimal_part_of_float_number_v2.c
- How can we extract the decimal part of a floating point number ?
- https://stackoverflow.com/questions/499939/how-to-extract-the-decimal-part-from-a-floating-point-number-in-c
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- #include<math.h>
- int main(void)
- {
- double x, fractpart, intpart;
- int int_part_x;
- x = -8.123456;
- int_part_x = (int)x;
- if(x<0)
- fractpart = - x + int_part_x;
- else
- fractpart = x - int_part_x;
- printf("\n %lf \t float number \n", x);
- printf("\n %d \t\t integral part \n", int_part_x);
- printf("\n %lf \t fraction part\n", fractpart);
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment