Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ round number down

#include <iostream>
#include <cmath>

using namespace std;

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

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 :: C++ mutex lock/unlock 
Cpp :: read struct from file c++ 
Cpp :: c++ random 
Cpp :: loop through char in string c++ 
Cpp :: c++ print number not in scientific notation 
Cpp :: cin.get vs cin.getline in c++ 
Cpp :: c++ int to string 
Cpp :: c++ competitive programming mst 
Cpp :: online cpp to exe converter 
Cpp :: how to add numbers in c++ 
Cpp :: if even number c++ 
Cpp :: convert long int to binary string c++ 
Cpp :: google pdf iframe viwer 
Cpp :: character array to string c++ stl 
Cpp :: C++ switch cases 
Cpp :: pbds in c++ 
Cpp :: string vector c++ 
Cpp :: arguments to a class instance c++ 
Cpp :: search a word in cpp file 
Cpp :: min heap and max heap using priority queue 
Cpp :: memset in c++ 
Cpp :: how to store pair in min heap in c++ 
Cpp :: c++ Program for Sum of the digits of a given number 
Cpp :: c++ isalphanum 
Cpp :: reading file c++ 
Cpp :: c++ remove text file 
Cpp :: 2d array c++ 
Cpp :: how to use cout function in c++ 
Cpp :: sorting using comparator in c++ 
Cpp :: iterate through map c++ 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =