dmilicev

integer_and_decimal_part_of_float_number_v1.c

Sep 15th, 2020
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     integer_and_decimal_part_of_float_number_v1.c
  4.  
  5.     How can we extract the decimal part of a floating point number ?
  6.  
  7.     https://stackoverflow.com/questions/499939/how-to-extract-the-decimal-part-from-a-floating-point-number-in-c
  8.  
  9.     C library function modf()
  10.     double modf(double x, double *integer)
  11.     https://www.tutorialspoint.com/c_standard_library/c_function_modf.htm
  12.  
  13.  
  14.     You can find all my C programs at Dragan Milicev's pastebin:
  15.  
  16.     https://pastebin.com/u/dmilicev
  17.  
  18. */
  19.  
  20. #include <stdio.h>
  21. #include<math.h>
  22.  
  23. int main(void)
  24. {
  25.     double x, fractpart, intpart;
  26.  
  27.     x = -8.123456;
  28.     fractpart = modf(x, &intpart);
  29.  
  30.     printf("\n %lf \t float number \n", x);
  31.     printf("\n %lf \t integral part \n", intpart);
  32.     printf("\n %lf \t fraction part\n", fractpart);
  33.  
  34.     return 0;
  35.  
  36. } // main()
  37.  
RAW Paste Data Copied