How to make cout not use scientific notation in C++

2 Answers

0 votes
#include <iostream>

int main() {
    float f = 16204000.95;

    std::cout << f << "\n";
    std::cout << std::fixed << f << "\n";

    return 0;
}


 
 
 
 
/*
run:
 
1.6204e+07
16204001.000000

*/

 



answered Jan 8, 2022 by avibootz
0 votes
#include <iostream>
#include <iomanip>
#include <locale>

int main() {
    float f = 16204000.95;
    
    std::cout.imbue(std::locale(""));
 
    std::cout << f << "\n";
    std::cout << std::fixed << std::setprecision(2) << f << "\n";
    
    f = 16204000.35;
    std::cout << std::fixed << std::setprecision(2) << f << "\n";

    return 0;
}


 
 
 
 
/*
run:
 
1.6204e+07
16,204,001.00
16,204,000.00

*/

 



answered Jan 8, 2022 by avibootz

Related questions

1 answer 203 views
1 answer 130 views
1 answer 159 views
1 answer 195 views
1 answer 210 views
2 answers 175 views
...