Re: [Dev-C++] Simple formatted output question
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luigi S. <gi...@li...> - 2002-11-09 03:57:42
|
On Wed, Nov 06, 2002 at 09:31:50PM -0500, Scott Williams wrote: > Hi, > > This is a "C" question (not C++). When printing a number in exponential > format (%e) using printf or one of its friends, three digits are used for > the exponent: > > 1.2345e+006. > > I would like to change this behavior so that the exponent only uses as many > digits as it needs: > > 1.2345e+6 > > I've looked, but this feature does not appear to be built into any of the > format modifiers/switches. Am I missing something and/or is there an easy > way to do this? > > Thnx, > Scott > Hi, Scott Assuming that by "C" you mean C89, the answer is: you are right, there seems to be no built-in way to achieve what you are looking for. However, an easy (probably too simple?) solution could be: - print the value into a string using scientific notation - erase unwanted extra leading zeroes in the exponent To better show the point, I attached an archive with: - a simple implementation of the above function - a short program to test the function - a file with some values I used for the test -- >> gisan >> So you're back... about time... |