# lround() function with example in C++

C++ lround() function: Here, we are going to learn about the lround() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on April 27, 2019

## C++ lround() function

lround() function is a library function of cmath header, it is used to round the given value and casts to a long integer, it accepts a number and returns the integer (long int) value that is nearest to the number (with halfway cases).

Syntax of lround() function:

```    lround(x);
```

Parameter(s): x – is the number to round nearest to zero with halfway cases.

Return value: long int – it returns long int type value that is the rounded value of the number x.

Example:

```    Input:
float x = 2.3;
Function call:
lround(x);
Output:
2

Input:
float x = 2.8;
Function call:
lround(x);
Output:
3
```

### C++ code to demonstrate the example of lround() function

```// C++ code to demonstrate the example of
// lround() function

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

// main() section
int main()
{
float x;

x = 15.3;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;

x = 15.5;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;

x = 15.8;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;

x = -15.3;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;

x = -15.5;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;

x = -15.8;
cout<<"lround("<<x<<"): "<<lround(x)<<endl;

return 0;
}
```

Output

```lround(15.3): 15
lround(15.5): 16
lround(15.8): 16
lround(-15.3): -15
lround(-15.5): -16
lround(-15.8): -16
```

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates