modf() in C/C++

CC++Server Side Programming

The function modf() is used to split the passed argument in integer and fraction. It is declared in “math.h” header file for the mathematical calculations. It returns the fractional value of passed argument.

Here is the syntax of modf() in C language,

double modf(double value, double *integral_pointer);


value − The value which splits into integer and fraction.

integral_pointer − It points the integer part of argument after splitting.

Here is an example of modf() in C language,


 Live Demo

int main () {
   double val, x, res;
   val = 28.856;
   res = modf(val, &x);
   printf("Integral part of val : %lf\n", x);
   printf("Fraction Part of val : %lf \n", res);


Integral part of val : 28.000000
Fraction Part of val : 0.856000

In the above program, the function modf() is splitting the floating point number into integral part and fractional part. Three variables are declared as val, x and res. The variable res stores the value calculated by modf().

res = modf(val, &x);
Published on 05-Nov-2018 11:29:55