Scientific notation still not being fixed

Alright. This one is better explained when seen.




Code:




**********************************************




void baseconversion(int charvalue[30], int whichbase, int& arraylength) {

double total = 0, show;

double wtf_why_do_I_keep_turning_into_sci_not = 1234567;

for (int i = 0; i <= arraylength; i++)

{

cout << endl;

total = total + ( pow(whichbase, i) * charvalue[arraylength - i] );

show = total;

cout.unsetf(ios::scientific);

cout << total << endl;

cout << wtf_why_do_I_keep_turning_into_sci_not << endl;

cout.setf(ios::scientific);

cout << show << endl;




}

}




**********************************************




Output:




**********************************************




Base you are converting from (Max - 16); 16

Number in base 16: abcdef




/*
What the program should do at this point is print out the total after each calculation. After this, I have a normal number that shouldn't change at all, not print into scientific notation. This is confusing because when I have the number under 1,000,000, the number prints normally, but the millions place immediately goes into this notation. I finally have the number switch into scientific notation, print it, then go back to not and it works fine. This is weird because once the number peaks 1 mil, it starts going into Scientific notation for an unknown reason
*/




15 //total non sci not

1.23457e+06

1.500000e+01 //total sci not




239 //total non sci not

1.23567e+06

2.390000e+03 //total sci not


etc.


/*
suddenly, the number will switch over to scientific notation when it's being told specifically not to
*/

1.27453e+07
1.23457+06
1.27453e+07


**********************************************




What have I don't wrong to cause this? I don't want the repeating zeroes and a decimal with Cout.setf(iOS::fixed), and this is working out even worse. Is there any way to show just the normal value without all the intrusive zeroes or scientific notations? I'd appreciate any response, thank you.
It will switch to scientific notation if it's necessary in order to prevent that the number of digits exceed the precision value.

http://www.cplusplus.com/reference/ios/ios_base/precision/
@Peter87 I appreciate the help, though I'm not seeing how I would apply this since the numbers I am working with do not have decimals, and setprecision(1) will just give me a 0 at the end, no? Sorry. I'm just trying to fully grasp this
Hi,

Have a read of this:

http://www.cplusplus.com/reference/ostream/ostream/

Good Luck !!
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main()
{
    for( double value : { 0.1, 123.4, 123456.7, 123456789.0, 1234567890123456.7 } )
    {
        std::cout << "    default: " << std::defaultfloat << value << '\n'
                  << "      fixed: " << std::fixed << value << '\n'
                  << " scientific: " << std::scientific << value << '\n'
                  << "hexadecimal: " << std::hexfloat << value << '\n'
                  << "----------------------------\n" ;
    }
}

    default: 0.1
      fixed: 0.100000
 scientific: 1.000000e-01
hexadecimal: 0x1.999999999999ap-4
----------------------------
    default: 123.4
      fixed: 123.400000
 scientific: 1.234000e+02
hexadecimal: 0x1.ed9999999999ap+6
----------------------------
    default: 123457
      fixed: 123456.700000
 scientific: 1.234567e+05
hexadecimal: 0x1.e240b33333333p+16
----------------------------
    default: 1.23457e+08
      fixed: 123456789.000000
 scientific: 1.234568e+08
hexadecimal: 0x1.d6f3454p+26
----------------------------
    default: 1.23457e+15
      fixed: 1234567890123456.750000
 scientific: 1.234568e+15
hexadecimal: 0x1.18b54f22aeb03p+50
----------------------------

http://rextester.com/IAXI81105
Topic archived. No new replies allowed.