I am currently using
std::cout.precision(5);
to set the decimal precision of my outputs. However, I would rather have my output ALWAYS output 5 decimal places (right now it won't show 0's). How would I change my code to reflect this?
You are looking for std::fixed
together with std::setprecision
.
#include <iomanip>
#include <iostream>
double f =1.1;
std::cout << std::fixed;
std::cout << std::setprecision(5) << f << std::endl;
stdout
1.10000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With