If you just want to round the number for output purposes, then the "%.2f" format string is indeed the correct answer. However, if you actually want to round the floating point value for further computation, something like the following works:

#include <math.h>

float val = 37.777779;

float rounded_down = floorf(val * 100) / 100;   /* Result: 37.77 */
float nearest = roundf(val * 100) / 100;  /* Result: 37.78 */
float rounded_up = ceilf(val * 100) / 100;      /* Result: 37.78 */

Notice that there are three different rounding rules you might want to choose: round down (ie, truncate after two decimal places), rounded to nearest, and round up. Usually, you want round to nearest.

As several others have pointed out, due to the quirks of floating point representation, these rounded values may not be exactly the "obvious" decimal values, but they will be very very close.

For much (much!) more information on rounding, and especially on tie-breaking rules for rounding to nearest, see the Wikipedia article on Rounding.

Answer from Dale Hagglund on Stack Overflow
๐ŸŒ
Quora
quora.com โ€บ How-do-I-display-floating-number-with-2-decimal-places-in-c
How to display floating number with 2 decimal places in c - Quora
Here's a good tutorial on format ... a floating-point number with exactly two decimal places in C, use the printf family with the "%.2f" format specifier....
Discussions

c - how to print float value upto 2 decimal place without rounding off - Stack Overflow
For example I want to print a value in c up to 2 decimal places, without rounding it off. like: a = 91.827345; printf("%.2f", a); will print 91.83, but I want output to be 91.82 only. How to do it? More on stackoverflow.com
๐ŸŒ stackoverflow.com
c++ - Two decimal places using printf( ) - Stack Overflow
# ./printf When this number: -1243822529 is assigned to 2 db, it will be: 2-0.000000 ... the -1234... part is the representation of your 32 bit floating point as an integer. The second part is wrong you should have %2.2f, but still I can't explain the -0.0000... More on stackoverflow.com
๐ŸŒ stackoverflow.com
arduino uno - Only 2 decimal places in printed float - Arduino Stack Exchange
There was a similar thread before but it didn't solve my problem. I had an issue with sending GPS data, which is float, and I couldn't receive the float with the same amount of significant figures ... More on arduino.stackexchange.com
๐ŸŒ arduino.stackexchange.com
July 24, 2017
Rounding two decimal places using Printf
Look up printf format strings (possibly in C, the syntax is the same). More on reddit.com
๐ŸŒ r/learnprogramming
5
1
September 22, 2015
๐ŸŒ
CCS, Inc.
ccsinfo.com โ€บ forum โ€บ viewtopic.php
CCS :: View topic - Float Values in Printf() upto 2 decimal values
April 4, 2007 - Profile Log in to check your private messages Log in ยท CCS does not monitor this forum on a regular basis
๐ŸŒ
Oxford University
mathcenter.oxford.emory.edu โ€บ site โ€บ cs170 โ€บ printf
The printf Method
we now see that the format specifier "%.2f" tells the printf method to print a floating point value (the double, x, in this case) with 2 decimal places.
๐ŸŒ
IncludeHelp
includehelp.com โ€บ c โ€บ how-to-print-float-value-till-number-of-decimal-points-using-printf.aspx
How to print float value till number of decimal points using printf in C language?
September 7, 2017 - Consider the program, here we will print 2 digits after the decimal point. #include <stdio.h> int main() { float num = 10.23456f; printf("num = %.2f\n",num); return 0; }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ rounding-floating-point-number-two-decimal-places-c-c
Rounding Floating Point Number To two Decimal Places in C and C++ - GeeksforGeeks
May 21, 2024 - #include <iostream> using namespace std; float round(float var) { // we use array of chars to store number // as a string. char str[40]; // Print in string the value of var // with two decimal point sprintf(str, "%.2f", var); // scan string value in var sscanf(str, "%f", &var); return var; } int main() { float var = 37.66666; cout << round(var); return 0; } Output: 37.67 ยท
Find elsewhere
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 3108546 โ€บ how-to-f-to-output-the-desired-digit-of-decimal-floatsaka-after-point
How to %f to output the desired digit of decimal & floats(aka after point) | Sololearn: Learn to code for FREE!
November 30, 2022 - printf("%x.yf", number); where x is the amount of digits you want to print before the point and y the amount of digits after the point ... "2.2f" => here before point 2 is the *maximum* length formatted to, for the float value.
๐ŸŒ
YouTube
youtube.com โ€บ coffee programmer
C Programming Limiting floats to two decimal places - How to limit and display float variable values - YouTube
Can you help me to buy a coffee:https://www.buymeacoffee.com/coffeeprogram how to limit float to 2 decimal places in c
Published ย  October 12, 2022
Views ย  2K
๐ŸŒ
Quora
quora.com โ€บ How-do-I-round-off-a-float-to-2-decimal-points-in-C-like-3-01943-to-3-02
How to round off a float to 2 decimal points in C, like 3.01943 to 3.02 - Quora
Answer (1 of 7): If you have to round input floating point number then for that the format is โ€œ%wfโ€ where w = Integer number for total width of data.(including the digit before and after decimal and decimal itself) Ex- scanf(โ€œโ€,&x) For x = 3.01943 Result = 7.8 If you have to round output fl...
๐ŸŒ
CopyProgramming
copyprogramming.com โ€บ howto โ€บ how-to-get-float-value-with-two-decimal-values-in-c-language
Obtaining a floating-point value with two decimal places in the C programming language
September 21, 2023 - In C language, I prefer extracting a floating-point value with two decimal places. ... Please ensure that the code math.h and action header file are both included and executed. float f; f = 2.3678; f = floor(f * 100) / 100; // f = 2.36 ... Setting decimal precision in C, Rounding is not required.
๐ŸŒ
Teasdalelatinfoods
teasdalelatinfoods.com โ€บ explorer โ€บ wiki โ€บ c-print-float-to-2-decimal-places-a8dfc0
c print float to 2 decimal places
In C, there is a format specifier ... changes to either 1.000 or 2.000 depending on what is on A0. To parse float with two decimal places, use the concept of toFixed(2)....
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 3253699 โ€บ how-to-print-floating-value-of-only-last-2-round-points-in-c
How to print floating value of only last 2 round points in c++? | Sololearn: Learn to code for FREE!
November 27, 2023 - Here suppose a is float a = 500/33; If now I print a with c++ code cout << a; It will print 15.1515 But I just want to print only 15.15 Only the last 2 digits after the frictional period.
๐ŸŒ
Northern Michigan University
nmu.edu โ€บ Webb โ€บ ArchivedHTML โ€บ MathComputerScience โ€บ c_programming โ€บ c_008.htm
More About Float and Double Variables
To change the number of decimal places printed out for float or double variables, modify the %f or %e to include a precision value, eg, ... In this case, the use of %.2f limits the output to two decimal places, and the output now looks like
๐ŸŒ
CodePal
codepal.ai โ€บ code-generator โ€บ query โ€บ XuhluRJK โ€บ c-code-formatted-output
C Code: Format and Print Float Variable with 2 Decimal Places - CodePal
*/ void printFloatWithTwoDecimalPlaces(float x) { printf("The value of x is: %.2f\n", x); } int main() { float x = 3.14159265; // Define the variable x. // Print the value of x with 2 decimal places. printFloatWithTwoDecimalPlaces(x); return 0; } ...
๐ŸŒ
Smith College
science.smith.edu โ€บ ~jfrankli โ€บ 231f13 โ€บ 231 โ€บ format.html
Formatting in printf, in C
For example, printf("The value is .6lf",myDoubleNum); causes the double precision value in the variable myDoubleNum to be printed out using 10 characters including the decimal point, with 6 number characters following the decimal point. Recall that the lf coming after the 10.6 stands for long float, or double precision.
๐ŸŒ
Texas Instruments E2E
e2e.ti.com โ€บ support โ€บ tools โ€บ code-composer-studio-group โ€บ ccs โ€บ f โ€บ code-composer-studio-forum โ€บ 804426 โ€บ ccs-cc2640r2f-printing-2-decimal-places-using-display_printf
Printing 2 decimal places using Display_printf - Code ... - TI E2E
May 23, 2019 - If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question. ... I need to print the float value upto 2 decimal places. I am using Display_printf function to print the result.