Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ round number to whole

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double num1 = 4.8;
  	double num2 = 4.3;
  	cout << round(num1) << endl; // --> 5
  	cout << round(num2) << endl; // --> 4
}
Comment

c++ round number up

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double num1 = 4.8;
  	double num2 = 4.3;
  	cout << ceil(num1) << endl; // --> 5
  	cout << ceil(num2) << endl; // --> 5
}
Comment

c++ round to whole number

#include <iostream>
#include <cmath>
using namespace std;

int main() {

  // display integral value closest to 15.5
  cout << round(15.5);

  return 0;
}

// Output: 16
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp float to int 
Cpp :: Matrix multiply using function c++ 
Cpp :: Write C++ program to copy one string to another string using pointers 
Cpp :: prime number in c++ 
Cpp :: c++ find largest number in array 
Cpp :: c++ check if string contains non alphanumeric 
Cpp :: easy c++ code 
Cpp :: c++ vector iterator 
Cpp :: c++ main function 
Cpp :: arduino notone 
Cpp :: format string cpp 
Cpp :: how to get a letter from the users string in c++ 
Cpp :: how to run a c++ program in the background 
Cpp :: c++ evaluate expression 
Cpp :: switch case with string c++ 
Cpp :: vector erase specific element 
Cpp :: c++ vector sort 
Cpp :: c++ case 
Cpp :: sort using lambda c++ 
Cpp :: split string on character vector C++ 
Cpp :: rand c++ 
Cpp :: c++ get full line of input 
Cpp :: how to get an element in a list c++ 
Cpp :: C++ std::string find and replace 
Cpp :: splice string in c++ 
Cpp :: the code execution cannot proceed because glew32.dll was not found 
Cpp :: how to print in cpp 
Cpp :: lutris 
Cpp :: c++ vector push if not exist 
Cpp :: iterate over vector in c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =