modf function(Split into Integer and Fractional Parts) in C Language – example and detail

In the C Programming Language, the modf characteristic splits a floating-point fee into an integer and a fractional part. The fraction is returned through the modf function and the integer section is stored in the iptr variable.


The syntax for the modf function in the C Language is:

double modf(double value, double *iptr);

Parameters or Arguments

value The floating-point fee to split into an integer and a fractional part. iptr A pointer to a variable where the integer phase will be stored.


The modf feature returns the fractional section of value.

Required Header

In the C Language, the required header for the modf function is:

#include <math.h>

Applies To

In the C Language, the modf function can be used in the following versions:

ANSI/ISO 9899-1990

modf Example

/* Example using modf by */

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
    /* Define temporary variables */
    double value;
    double i, f;

    /* Assign the value we will calculate the modf of */
    value = 1.7;

    /* Calculate the modf of the value returning the fractional and integral parts */
    f = modf(value, &i);

    /* Display the result of the calculation */
    printf("The Integral and Fractional parts of %f are %f and %f\n", value, i, f);

    return 0;

When compiled and run, this software will output:

The Integral and Fractional parts of 1.700000 are 1.000000 and 0.700000

Similar Functions

Other C functions that are similar to the modf function:

frexp function <math.h>