floor()

floor ist definiert in der math, die in C über math.h, bzw. in C++ über cmath eingebunden wird.

Funktion

floor() rundet den übergebenen Fließkommawert auf die nächst kleinere natürliche Zahl. Die Nachkommastellen werden gewissermaßen weggelassen. Zurückgegeben wird ebenfalls als Fließkommazahl.

Signatur

#include <math.h>
double      floor(      double x );
float       floor(       float x );
long double floor( long double x );

x: der abzurundende Wert

Return value: Der zur nächst kleineren natürlichen Zahl abgerundete Wert.

Fehlerquellen

-

Beispiel

#include <stdlib.h> // für EXIT_SUCCESS
#include <math.h>   // für floor
#include <stdio.h>  // für printf()
 
int main( void )
{
  printf( "floor(  1.1 ) : %f\n", floor(  1.1 ) );
  printf( "floor(  1.9 ) : %f\n", floor(  1.9 ) );  
  printf( "floor( -1.1 ) : %f\n", floor( -1.1 ) );  
  printf( "floor( -1.9 ) : %f\n", floor( -1.9 ) );
 
  return EXIT_SUCCESS; 
}

Ausgabe:

floor(  1.1 ) : 1.0
floor(  1.9 ) : 1.0
floor( -1.1 ) : -2.0
floor( -1.9 ) : -2.0

siehe auch