C++ Math round()

Last Updated : 21 May 2026

Math round() Function

In C++, the round() function is defined in the <cmath> or <math.h> header file and is used to round a floating-point value to the nearest integer. If the fractional part is 0.5 or greater, the value is rounded away from zero.

The round() function supports float, double, and long double values.

For example

Syntax

It has the following syntax.

Parameters

x : The value which can be either float or double.

Return value

It returns the rounded value of x. The return type of the value can be float, double or long double.

Examples of the List round() Function

Here, we are going to discuss several examples to demonstrate the List round() Function Function.

Example 1: Round a Positive Floating-Point Value Using round()

This example demonstrates how the round() function rounds a positive floating-point value to the nearest integer.

Output:

The value of x is : 8.3
Rounded value of x is : 8   

Example 2: Round a Negative Floating-Point Value Using round()

This example demonstrates how the round() function behaves when the input value is negative.

Output:

The value of x is : -9.9
Rounded value of x is : -10

Example 3: Use round() with an Integer Value

This example demonstrates how the round() function behaves when the input value is already an integer. In this case, the same value is returned.

Output:

The value of x is : 12
Rounded value of x is : 12