English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and Example of C Library Function modf()

C Standard Library - <math.h>

C Library Function double modf(double x, double *integer) Returns the fractional part (the part after the decimal point), and sets integer to the integer part.

Declaration

Declaration of modf() function

double modf(double x, double *integer)

Parameter

  • x  -- Floating-point value.

  • integer  -- A pointer to an object that stores the integer part.

Return Value

This function returns the fractional part of x, with the same sign as x.

Online Example

The following example demonstrates the usage of the modf() function.

#include<stdio.h>
#include<math.h>
int main()
{
   double x, fractpart, intpart;
   x = 9.87654321;
   fractpart = modf(x, &intpart);
   printf("Integer part = %lf\n", intpart);
   printf("Decimal Part = %lf \n", fractpart);
   
   return(0);
}

Let's compile and run the above program, which will produce the following result:

Integer Part = 9.000000
Decimal Part = 0.876543

C Standard Library - <math.h>