EnderEgg
EnderEgg

Reputation: 335

How to display a float with no decimal digits in 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

Upvotes: 4

Views: 13758

Answers (1)

FatalError
FatalError

Reputation: 54551

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).

Upvotes: 16

Related Questions