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 firstname.lastname@example.org. 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.
- How to count set bits in a floating point number in C?
- Convert a floating point number to string in C
- Can we use % operator on floating point numbers?
- C Program to Multiply two Floating Point Numbers
- Floating Point Operations & Associativity in C, C++ and Java
- Problem in comparing Floating point numbers and how to compare them correctly?
- Write a one line C function to round floating point numbers
- Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())
- sizeof() for Floating Constant in C
- How Linkers Resolve Global Symbols Defined at Multiple Places?
- Setting decimal precision in C
- What is the best way in C to convert a number to a string?
- Program for Sum of the digits of a given number
- Sorting 2D Vector in C++ | Set 3 (By number of columns)
- Count number of unique Triangles using STL | Set 1 (Using set)
Improved By : arjunaggarwal