floor function(Floor) in C Language – example and detail

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

Syntax

The syntax for the ground characteristic 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 characteristic returns the biggest integer that is smaller than or equal to x.

Required Header

In the C Language, the required header for the ground feature is:

#include <math.h>

Applies To

In the C Language, the flooring 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 utility will output:

The floor of 1.600000 is 1.000000

Similar Functions

Other C functions that are comparable to the floor function:

ceil function <math.h>