C Floor Function: Complete Guide

In C language, the floor function is used to round down, returning the largest integer value that is less than or equal to the given parameter. The specific usage is as follows:

#include <math.h>

double floor(double x);

Parameter x is the value that needs to be rounded, and the return value is the maximum integer value of type double.

Example:

I cannot attend the meeting tomorrow due to a scheduling conflict.

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

int main() {
    double x = 3.14;
    double result = floor(x);
    
    printf("向下取整的结果为: %f\n", result);
    
    return 0;
}

In the above example, using the floor function on 3.14 results in 3.0.

bannerAds