How to use floor() function to round N downward to the largest value that is not greater than N in C++

1 Answer

0 votes
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	cout << "floor(1.3) = " << floor(1.3) << endl;
	cout << "floor(2.7) = " << floor(2.7) << endl;
	cout << "floor(-4.2) = " << floor(-4.2) << endl;
	cout << "floor(-2.8)  = " << floor(-2.8) << endl;
	cout << "floor(-0.0) = " << floor(-0.0) << endl;

	return 0;
}

/*
run:

floor(1.3) = 1
floor(2.7) = 2
floor(-4.2) = -5
floor(-2.8)  = -3
floor(-0.0) = -0

*/

 



answered Mar 16, 2016 by avibootz
...