Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

three digits for the exponent in float/double numbers

368 views
Skip to first unread message

denic

unread,
Feb 25, 2002, 10:54:30 AM2/25/02
to
Hello !

*file<<uppercase<<scientific<<value

if value=0.01;
On Visual Studio C++, this line will generate this output :
1E-002

I would like to have 2 digits for the exponent only .
How can I do that ? May I use fprintf instead ??!

Thanks for your help
And sorry for my english !

Victor Bazarov

unread,
Feb 25, 2002, 2:31:23 PM2/25/02
to
"denic" <den...@yahoo.fr> wrote...

> *file<<uppercase<<scientific<<value
>
> if value=0.01;
> On Visual Studio C++, this line will generate this output :
> 1E-002
>
> I would like to have 2 digits for the exponent only .
> How can I do that ? May I use fprintf instead ??!


Convert it to float. Number of digits in the exponent
depends on the range, I guess.

Victor
--
Please remove capital A's from my address when replying by mail


Jack Klein

unread,
Feb 25, 2002, 11:23:13 PM2/25/02
to
On 25 Feb 2002 07:54:30 -0800, den...@yahoo.fr (denic) wrote in
comp.lang.c++:

The C standard that Visual C++ claims to conform to, and mostly does,
specifies that scientific notation output must contain at least two
digits in the exponent. It does not place a maximum value, and many
compilers use at least three.

The 1999 update to the C standard requires that a compiler provide at
least two digits, and no unnecessary leading zeros beyond two digits,
but Visual C++ does not even attempt to conform to this standard
version.

I believe Visual C++ will generate three digits for any of the
*printf() family functions as well. If you must have only two digits,
use a C or C++ function to format the output into a std::string or
character array, for example sprintf(), and modify the resulting
string to remove the extra '0' before outputting to the file.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

0 new messages