What is llround() function in C++?

llround() is the built-in C++ function. It is used to round off the specified number to the nearest value.

Syntax

long long int llround(datatype number)

Here datatypes can be:

  • double
  • float
  • long double

You have to include math.h in order to use this function.

Return

It returns long long integer, which comprises of 8 bytes.

Code

double

#include <iostream>
#include<math.h>
using namespace std;
int main() {
double number = 380.555;
cout <<"The number is :" << number << endl;
cout << "The llround() is :"<< llround(number) << endl;
return 0;
}

float

#include <iostream>
#include<math.h>
using namespace std;
int main() {
float number = 10.5;
cout <<"The number is :" << number << endl;
cout << "The llround() is :"<< llround(number) << endl;
return 0;
}

long double

#include <iostream>
#include<math.h>
using namespace std;
int main() {
long double number = 340.333333;
cout <<"The number is :" << number << endl;
cout << "The llround() is :"<< llround(number) << endl;
return 0;
}
Attributions:
  1. undefined by undefined
Copyright ©2024 Educative, Inc. All rights reserved