double floor(double
x
);
float floorf(float x); long double floorl(long double x);
double floor(double x);
double ceil(double x);
USES the floor function. Floor (x) returns the largest integer less than or equal to x.
such as: floor ten floor (10.5) = = = = (10.5) – 11
USES the ceil function. Ceil (x) returns the smallest integer greater than x.
for example: ceil(10.5) == 11 ceil(-10.5) ==-10
floor() is rounded to negative infinity, floor(-10.5) == -11;
ceil() is rounded to positive infinity, and ceil(-10.5) == -10
(ceil()) (floor) (floor)
1. /
//Test “/”
cout & lt; < “Test \”/\”!” < < endl;
cout & lt; < “7/2 =” < < 7/2 < < endl;// 3
cout & lt; < “7/2.0 =” < < 7/2.0 & lt; < endl;// 3.5
cout & lt; < “7.0/2 =” < < 7.0/2 & lt; < endl;// 3.5
cout & lt; < “7.0/2.0 =” < < 7.0/2.0 & lt; < endl;// 3.5
cout & lt; < “7/3 =” < < 7/3 < < endl;// 2
cout & lt; < endl;
2. %
//Test “%”
cout < < “Test \”%\”!” < < endl;
cout & lt; < 9%3 = “< < 9%3 < < endl;// 0
cout & lt; < “9%4 = “< < 9%4 < < endl; 1
//// cout & lt; < “9.0% 3 =” < < 9.0% 3 & lt; < endl;
// cout & lt; < 9%3.0 = “< < 9% 3.0 & lt; < endl;
cout & lt; < endl;
3. Round
//Test round()
cout < < “Test \” Round \”!” < < endl;
double dRoundA = 1.4;
double dRoundB = 1.6;
double dRoundLowA = -1.4;
double dRoundLowB = -1.6;
double dRoundLowC = 0.0;
cout & lt; < dRoundA < < ” = ” < < RoundEx(dRoundA) < < endl;// 1
cout & lt; < dRoundB < < ” = ” < < RoundEx(dRoundB) < < endl;// 2
cout & lt; < dRoundLowA < < ” = ” < < RoundEx(dRoundLowA) < < endl;// – 1
cout & lt; < dRoundLowB < < ” = ” < < RoundEx(dRoundLowB) < < endl;// – 2
cout & lt; < dRoundLowC < < ” = ” < < RoundEx(dRoundLowC) < < endl;// 0
cout & lt; < endl;
double RoundEx(const double&
{
double dIn = dInput;
if (dInput & gt; = 0.0)//???
{
return int(dIn + 0.5);
} else
{
return int (dIn 0.5);
}}
4. The ceil () take up the whole
// Test ceil () take up the whole
cout & lt; < “Test ceil() round up!” < < endl;
cout & lt; < “Ceil 1.2 =” < < The ceil (1.2) & lt; < endl;// 2
cout & lt; < “Ceil 1.8 =” < < The ceil (1.8) & lt; < endl;// 2
cout & lt; < “Ceil-1.2 =” < < The ceil (1.2) & lt; < endl;// – 1
cout & lt; < “Eil-1.8 =” < < The ceil (1.8) & lt; < endl;// – 1
cout & lt; < “Ceil 0.0 =” < < The ceil (0.0) & lt; < endl;// 0
cout & lt; < endl;
5. Floor () the whole
/down/Test floor () the whole down
cout & lt; < “Test floor() down full!” < < endl;
cout & lt; < “Floor 1.2 =” & LT; < Floor (1.2) & lt; < endl;// 1
cout & lt; < “Floor 1.8 =” < < Floor (1.8) & lt; < endl;// 1
cout & lt; < “Floor -1.2 =” < < Floor (1.2) & lt; < endl;// – 2
cout & lt; < “Floor -1.8 =” < < Floor (1.8) & lt; < endl;// – 2
cout & lt; < “Floor 0.0 =” < < Floor (0.0) & lt; < endl;// 0
cout & lt; < endl;
Read More:
- The difference of four kinds of integer function (fix floor ceil round) in MATLAB
- C / C + + rounding function: round function
- The usage of several integer functions in MATLAB (fix, floor, ceil, round)
- C / C + + library function (tower / tower) realizes the conversion of letter case
- C language string processing error warning, c4996, sprintf, predicted, c4996, strcpy, c4996, strcat
- The use of C + + template function and lambda expression
- C++:error C2228: left of ‘.str’ must have class/struct/union
- The C language qsort() function reports an error for overflow of – 2147483648 and 2147483648
- [C + +] C + + overload operator = must be a nonstatic member function?
- Differences between length() size() and C strlen() of C + + string member functions
- How to use C + + function pointer array
- error C4996: ‘scanf‘: This function or variable may be unsafe.Visual Studio Series compilers report errors using scanf function
- The function and usage of argc and argv in C language
- C language write() function analysis: write failed bad address
- Error c2137 of C language: empty character constant (Fixed)
- Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +
- Error c2064: term does not evaluate to a function in VC
- Solution to the flash of running result of dev C / C + +
- C / C + + error handling (document): unhandled exception: 0xc0000005: access violation while reading location 0x00000000
- Error C2664 in C + + compilation: cannot convert parameter 2 from “const char [5]” to “lpctstr” solution.