When ever I print a varible which is a float it always comes up with somthing like 5.5000000 is there a way to get rid of the zeros!!!
When ever I print a varible which is a float it always comes up with somthing like 5.5000000 is there a way to get rid of the zeros!!!
OS:- XP
Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)
Yup!
Limits the answer to 2 places after the decimal point.Code:printf("%.2f", answer);
Money frees you from doing things you dislike. Since I dislike doing nearly everything, money is handy - Groucho Marx
Yeah thanks but there is a slight problem. I don't know how many figures are going to be behind the decimal place (eg. the answer could be 5, 5.2, 5.6545, 5.364 etc.) so is there a way just to take off the useless and annoying zeros (eg. instead of having 5.3640000 have 5.364)????
Thanks
OS:- XP
Compiler:- MSVC++ 6 or DJGPP or Dev-c++ (Mingw)
Try %g.
Code:printf("%g", answer);