I am having trouble getting printf to print out my values correctly. In my program (calculator) I need to print out a load of numerical variables. Now, currently I use the %.*g printf flag, as %.*f is quite happy to 'pad' the value out with many 0's if it does not have '*' decimal places. %.*g does not do this, but it does like scientific notation. Why is this a problem? Well take a look at this:
Now, it gives me:Code:printf("%.*g", 16, tan(180 * 3.14159265358979323846 / 180)); //16 is the precision of a 64 bit double
Which is as good as 0 (the correct answer), however because (please correct me if I wrong) printf is printing out more digits than what a 64 bit double is accurate to you end up with a load of crap on the end which I really do not want. So, what should I do? I need a printf flag which is like %f but that does not append a load of 0's to the end, or should I just manually check for the input numbers and manually correct the output?