How to round off a floatig point value to two places. For example, 5.567 should become 5.57 and 5.534 should become 5.53
First Method:- Using Float precision
Second Method : Using integer typecast If we are in Function then how return two decimal point value
Third Method : using sprintf() and sscanf()
This article is contributed by Devanshu Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Convert a floating point number to string in C
- Can we use % operator on floating point numbers?
- Function Overloading and float in C++
- What happens if loop till Maximum of Signed and Unsigned in C/C++?
- Type Inference in C++ (auto and decltype)
- NaN in C++ - What is it and how to check for it?
- Data Type Ranges and their macros in C++
- Assigning an integer to float and comparison in C/C++
- Wide char and library functions in C++
- Comparison of boolean data type in C++ and Java
- Character arithmetic in C and C++
- Difference between float and double in C/C++
- Interesting facts about data-types and modifiers in C/C++
- Different ways to declare variable as constant in C and C++
- Is there any need of "long" data type in C and C++?
Improved By : arjunaggarwal