The float type of the data type displays decimal numbers. by default, my compiler displays up to 6 decimal places. I want to see only two decimal places. for example, when the compiler performs the operation "c = 2/3", it displays "0.666666667". I want to see only "0.67" on the output screen. so what changes need to be made to program C?
You can use the format specifier to limit it to 2 decimal places when outputting a number with printf.
printf
int main() { double d = 2.0 / 3.0; printf("%.2f\n",d); return 0; }
Here's the conclusion:
---------- Capture Output ---------- > "c:\windows\system32\cmd.exe" /c c:\temp\temp.exe 0.67 > Terminated with exit code 0.
, , , - printf("%f", x). "f" , , , printf("%.2f", x).
printf("%f", x)
printf("%.2f", x)
Print formatting for decimal places is%. followed by the amount of decimal precision followed by "f".
Thus, the display of two decimal places will be
printf("%.2f", i);
and displaying six decimal places will be
printf("%.6f", i);
Source: https://habr.com/ru/post/1759215/More articles:Connecting my Android phone to DDMS SDK utility - androidJava Host Architecture Architecture - javaстандарт для "циклов" в XML? - xmlPython and mySQLdb error: OperationalError: (1054, "Unknown column in the where section where") - pythonData structure for recognizing repetition values - c #How to group records by range in SQL - sqlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1759217/t-sql-query-always-returns-results-in-ssms-but-occasionally-fails-to-return-results-when-executed-through-net-via-adonet&usg=ALkJrhgaKsO8rNMjTT3JC8_MKWXTt3TE3AАутентификация "форм" Windows - Перенаправление на чужой странице! - authenticationGetChangeSet () request to search for a specific object? - linq-to-sqlWhy is an error message considered an error in ftplib - pythonAll Articles