How to round in scientific notation with C++

1 Answer

0 votes
#include <iostream>
#include <iomanip>
#include <cfenv>

int main()
{
    std::cout << std::setprecision(0) << std::scientific;

    std::fesetround(FE_DOWNWARD);
    std::cout << "round down: " << 0.52 << "\n";       

    std::fesetround(FE_UPWARD);
    std::cout << "round up: " << 0.52;           
}




/*
run:

round down: 5e-01
round up: 6e-01

*/

 



answered Jan 23, 2023 by avibootz

Related questions

1 answer 165 views
2 answers 255 views
1 answer 204 views
1 answer 211 views
2 answers 188 views
3 answers 293 views
...