C++ Standard Library C++ STL Library

C++ <cmath> - llround() Function

The C++ <cmath> llround() function rounds the specified number to a nearest integral value, rounding halfway cases away from zero, regardless of the current rounding mode and returns it as long long int type.

The lround() function is similar to this function, except it returns the result as long int type.


long long int llround (double x);
long long int llround (float x);
long long int llround (long double x);
long long int llround (T x);                  


x Specify a value to round.

Return Value

Returns the value of x which is first rounded to nearby integral value then casted to long long int type.


In the example below, llround() function is used to round the given number.

#include <iostream>
#include <cmath>

using namespace std;

int main (){

  cout<<"llround(10.2): "<<llround(10.2)<<"\n";
  cout<<"llround(10.8): "<<llround(10.8)<<"\n";
  cout<<"llround(-5.2): "<<llround(-5.2)<<"\n";
  cout<<"llround(-5.8): "<<llround(-5.8)<<"\n";
  return 0;

The output of the above code will be:

llround(10.2): 10
llround(10.8): 11
llround(-5.2): -5
llround(-5.8): -6

❮ C++ <cmath> Library