Math Lround Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Lround Function

Math Lround Function

BLUF: Mastering Math Lround Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Lround Function

C++ is renowned for its efficiency. Learn how Math Lround Function enables low-level control and high-performance computing in the tutorial below.

C++ Math lround

This function is employed to round the provided value and convert it to a long integer.

Syntax

Suppose a number is 'x'. Syntax would be:

Example

long int lround(data_type x);

Parameter

x : The value that can be either a float or double data type.

Return value

It provides the nearest whole number value of x. The function has a return type of long int.

Example 1

Let's explore a basic illustration of employing the lround function.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=2.3;
    double y=-12.6;
    float z=23.6;
    std::cout << "The value of x is : " <<x<< std::endl;
    std::cout << "The value of y is : " <<y<< std::endl;
    std::cout << "The value of z is : " <<z<< std::endl;
    cout<<"Rounded value of x is : "<<lround(x)<< std::endl;
    cout<<"Rounded value of y is : "<<lround(y)<< std::endl;
    cout<<"Rounded value of z is : "<<lround(z)<< std::endl;
    return 0;
}

Output:

Output

The value of x is : 2.3
The value of y is : -12.6
The value of z is : 23.6
Rounded value of x is : 2
Rounded value of y is : -13
Rounded value of z is : 24

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience