printing whole numbers as double
Apr 27, 2016 at 8:59am
I am trying to print a whole number as a double, using set precision and it does not work. It works for double number but not for whole numbers.
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
double val = 2.0;
std::cout << setprecision(3)<< val << endl;
return 0;
}
|
Last edited on Apr 27, 2016 at 9:00am
Apr 27, 2016 at 10:10am
You should use
fixed
Try doing this:
|
std::cout<<setprecision(3)<<fixed<<val<<endl;
|
Apr 29, 2016 at 2:12am
Thanks a lot that worked :)
Topic archived. No new replies allowed.