Home

Math Functions: The Floor of a Number

     

Introduction

Consider two floating numbers such as 128.44 and -36.72. The number 128.44 is between 128 and 129 with 128 being the lower. The number –36.72 is between –37 and –36 with –37 being the lower. The lowest but closest integer value of a number is referred to as its floor. Based on this, the floor of 128.44 is 128. The floor of –36.72 is –37.

   

The floor() Function

In C++, to obtain the floor of a number, use the following function:

double floor(double Value);

The floor() function takes the considered value as the argument and returns the integer that is less than or equal to Value. Here is an example:

//---------------------------------------------------------------------------

#include <vcl.h>
#include <math.h>
#pragma hdrstop

#include "Exercise.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmExercise *frmExercise;
//---------------------------------------------------------------------------
__fastcall TfrmExercise::TfrmExercise(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmExercise::btnFloorClick(TObject *Sender)
{
	double Number = edtNumber->Text.ToDouble();
	edtFloor->Text = floor(Number);
}
//---------------------------------------------------------------------------

Here is an example of running this code:

Floor

Floor

The Floor() Function

When using C++Builder, you can use the Floor() function to find the floor of a number. The syntax of the function is:

int __fastcall Floor(Extended Value);

The Value argument of the function represents the number that is being considered. The function returns the integer that is less than or equal to Value. Here is an example:

//---------------------------------------------------------------------------

#include <vcl.h>
#include <math.hpp>
#pragma hdrstop

#include "Exercise.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmExercise *frmExercise;
//---------------------------------------------------------------------------
__fastcall TfrmExercise::TfrmExercise(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmExercise::btnFloorClick(TObject *Sender)
{
	double Number = edtNumber->Text.ToDouble();
	edtFloor->Text = Floor(Number);
}
//---------------------------------------------------------------------------

Here is an example of running this code:

Floor

Floor

 

 

 
 
     
 

Home Copyright © 2010-2011 FunctionX, Inc.