June 27th, 2013, 01:29 PM
Float setting decimal places
I am trying to find out when using float in a calculation how to set the number of decimal places. For example my code below
printf("the answer is %f\n",answer);
This returns an answer 8487.0000 I would like it not to show all the decimal places. However if the sum has decimal places I would like to select the number of decimal places shown
June 28th, 2013, 08:32 AM
You can't do that with printf directives. You can sprintf to a string and manipulate in various ways.
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.
June 28th, 2013, 02:57 PM
I actually managed to get some help and read something on a tutorial and got it to work.
Originally Posted by DaWei_M
printf("the answer is %4.2f\n",answer);
now the plot thickens as I need to do it to several numbers.
Comments on this post