![]() |
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: Converting 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++.
Output The integer for float value 3.14 is 3 The integer for float value 9.99 is 10 Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 17 |