how am I supposed to print a float so as if it has no numbers behind decimal point e.g. 11.00 should be printed as 11 but 11.45 should stay the same. The problem is some if statement maybe. Any suggestions?
First solution that comes on my mind is cast. This is what I would do. Let's say your variable is "a", that you want to print.
float a;
if (if (a-(int)a<0.001 || (int)a-a<0.001) ) //1st comment explains this
printf("%d", (int)a);
else
printf("%f", a);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With