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.
- C Program to Multiply two Floating Point Numbers
- How to count set bits in a floating point number in C?
- Convert a floating point number to string in C
- Floating Point Operations & Associativity in C, C++ and Java
- Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())
- Problem in comparing Floating point numbers and how to compare them correctly?
- Write a one line C function to round floating point numbers
- Can we use % operator on floating point numbers?
- How Linkers Resolve Global Symbols Defined at Multiple Places?
- sizeof() for Floating Constant in C
- Setting decimal precision in C
- Swap two variables in one line in C/C++, Python, PHP and Java
- Add two numbers using ++ and/or --
- C program to compare two files and report mismatches
- To find sum of two numbers without using any operator
- How to concatenate two integer arrays without using loop in C ?
- How to sum two integers without using arithmetic operators in C/C++?
- Counts of distinct consecutive sub-string of length two using C++ STL
- C Program to merge contents of two files into a third file
- Modulus of two float or double numbers
Improved By : arjunaggarwal