Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a float with no decimal digits in C

Tags:

c

I want to print a float with no decimal digits. I know I can use another variable like int and make it the same, but I wanted to avoid that if there is something simpler (like %02f but to limit instead of being at least two digits long).

If there is no way then I'll use a variable int.

Thank you

like image 624
EnderEgg Avatar asked Sep 05 '25 11:09

EnderEgg


1 Answers

You want something like

printf("%.0f\n", my_float);

This will tell printf to include 0 decimal places of precision (you can, of course, use other values as well).

like image 140
FatalError Avatar answered Sep 09 '25 00:09

FatalError