totn C Functions

C Language: floor function
(Floor)

In the C Programming Language, the floor function returns the largest integer that is smaller than or equal to x (ie: rounds downs the nearest integer).

Syntax

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

double floor(double x);

Parameters or Arguments

x
The value to round down to the nearest integer.

Returns

The floor function returns the largest integer that is smaller than or equal to x.

Required Header

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

#include <math.h>

Applies To

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

  • ANSI/ISO 9899-1990

floor Example

/* Example using floor by TechOnTheNet.com */

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

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

    /* Assign the value we will find the floor of */
    value = 1.6;

    /* Calculate the floor of value */
    result = floor(value);

    /* Display the result of the calculation */
    printf("The floor of %f is %f\n", value, result);

    return 0;
}

When compiled and run, this application will output:

The floor of 1.600000 is 1.000000

Similar Functions

Other C functions that are similar to the floor function: