get rid of exponential form

i am getting a double value as this 3.46969e+06.

how to make it to a normal form as 3469692.6031362
i can print it in correct form using cout.precision(15) or something

but cannot use the value when it is used for processing it is shown as 3.46969e+06

any help will be greatly appreciated.

Thanks in advance
If you get the correct form with the precision as 15, then that is what is stored in the double correctly. The value you see in in scientific notation and it trims it down for printing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Test
#include <iostream>
#include <iomanip>

int main()
{
  long double d = 3469692.6031362;
  std::cout << d << std::endl;
  std::cout << std::fixed;
  std::cout << d << std::endl;
  std::cout << std::setprecision(9) << std::showpoint;
  std::cout << d << std::endl;
  
  return 0;
}


It prints the correct value, but when you cout without precision it chops it off. That doesn't mean the number is smaller or incorrectly stored.

3.46969e+006
3469692.603136
3469692.603136200

Process returned 0 (0x0)   execution time : 0.010 s
Press any key to continue.
one more doubt
d holds which value 3469692.603136 or 3.46969e+006
i dont need to print in correct form but to use it as 3469692.603136
Is it possible. is there any compiler option to do it
d holds the correct value 3469692.603136. That is show by the printing I did.
If you use d in an expression it will use the full value of d, not the e+006. When you print it it will chop it off and make it into e+00x (x being some number). You will need to set the precision and make it a fixed decimal to display correctly.

It will use the correct value for d.
Proof:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Test
#include <iostream>
#include <iomanip>

int main()
{
  long double d = 3469692.6031362;

  d /= 2.123;

  std::cout << std::setprecision(9) << std::showpoint << std::fixed;
  std::cout << d << std::endl;

  return 0;
}

1634334.716503156

Process returned 0 (0x0)   execution time : 0.017 s
Press any key to continue.
Last edited on
Topic archived. No new replies allowed.