How to Convert Float to int in C++? Last Updated : 21 May, 2024 Comments Improve Suggest changes Like Article Like Report In C++, the float is a short term for floating point value that is used to define numeric values with decimal points. The floating point numbers can be converted to integers using the process called type casting. In this article, we will learn how to convert a float value to an int in C++. Example: Input:float val1 = 3.14;float val2 = 9.99;Output:Integer for float value 3.14 is: 3Integer for float value 9.99 is: 10Converting From Float to int in C++ To convert a floating value to an int value, first use the std::round() function that rounds the float to the nearest whole number, and then we can use the static_cast operator to cast the result to an integer. Syntax to Convert Float to int in C++ int intValueName = static_cast<int>(round(floatValueName)); C++ Program to Convert Float to intThe below program demonstrates how we can convert a floating value to an integer in C++. C++ // C++ program to convert float to int using std::round and // casting #include <cmath> #include <iostream> using namespace std; int main() { // Define float values float floatValue1 = 3.14; float floatValue2 = 9.99; // Use std::round and static_cast to convert the float // values to int type int intValue1 = static_cast<int>(round(floatValue1)); cout << "The integer for float value " << floatValue1 << " is " << intValue1 << endl; int intValue2 = static_cast<int>(round(floatValue2)); cout << "The integer for float value " << floatValue2 << " is " << intValue2 << endl; return 0; } OutputThe integer for float value 3.14 is 3 The integer for float value 9.99 is 10 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Convert Float to int in C++? H heysaiyad Follow Improve Article Tags : C++ Programs C++ CPP Examples Practice Tags : CPP Similar Reads Convert Float to String In C++ In this article, we learn how we can convert float to string in C++ using different methods: Using the to_string()Using stringstreamUsing MacrosUsing lexical_cast from the boost library1. Using to_string() The to_string() method takes a single integer variable or other data type and converts it into 3 min read How to Convert wstring to int in C++? In C++, std::wstring is a type of string where each character is of a wide character type. These types of strings can be used to store the numerical strings which can then be converted to their corresponding type. In this article, we will see how to convert a wstring to an int in C++. Input: wstr = 2 min read How to Convert Char Array to Int in C++ In C++, a character array is treated as a sequence of characters also known as a string. Converting a character array into an integer is a common task that can be performed using various methods and in this article, we will learn how to convert char array to int in C++. Example Input:char arr1[] ="1 2 min read How to Convert wstring to double in C++ In C++, std::wstring is a type of string where each character is of a wide character type. Converting wstring to a double in C++ can be a common requirement especially when dealing with the inputs that are stored as unicode characters. In this article, we will learn how to convert a wstring to a dou 2 min read How to Catch Floating Point Errors in C++? In C++, a part of the code that may throw exceptions is enclosed in try-and-catch blocks to handle them when they arise. We can also use try...catch to catch floating point errors but it involves a bit different approach in comparison to catching standard exceptions. In this article, we will look at 2 min read Like