Greetings,
How do I get a float that if the answer is a whole number to not
print .0 at the end of it.
Example if the result is 4.5 print 4.5 but if the result is 4.0 print 4
Does anyone have a list of refernces for basic C programming? In
particular some that deal with the very cool but very basic tools
such as printf ? I don't, off the top of my head.
Basically, you can do this kind of thing:
float foo = 3.14;
printf("%f", foo); -> 3.14
printf("%2.3f", foo); -> 03.140
printf("%.0f", foo); -> 3
Those numbers tell printf how many "places" to display.
There's actually a hell of a lot of little thingies like that you
can do, but I'd need to look most of them up.
So to answer the question, here's a horrid example:
(using 'foo' again)
if (foo == (long)foo)
printf("%.0f", foo);
else
printf("%f", foo);
I have little-to-no doubt that someone will have a better
solution.
Cheers,
Matty
--
The one French thing I like is the phrase: c'est la vie
It's so.. fatalistic. So hopeless. This is life.Z
_________________________________________________________________
E-mail just got a whole lot better. New ninemsn Premium. Click here
http://ninemsn.com.au/premium/landing.asp