+ 2

Set precision for all variables in one step

How can I use std::setprecision on all variables of type double in my C++ program in a single step, without using it on each variable one by one? Do I need a typedef or something?

18th Aug 2018, 3:30 AM
Moses Odhiambo
Moses Odhiambo - avatar
3 odpowiedzi
+ 2
Moses Odhiambo don't use serprecision with cout in conjunction with variable to be output... just do it once individually and all following variable will follow the same. Refer below code : double a = 2.345; double b = 3.4556789; cout << setprecision(3); cout << a << endl; // prints 2.35 cout << b << endl; // prints 3.46 Correct me if I misunderstood your question...
18th Aug 2018, 4:50 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Ketan Lalcheta you should be a moderator.
18th Aug 2018, 5:34 AM
Moses Odhiambo
Moses Odhiambo - avatar
0
Moses Odhiambo I am looking for that honour...
18th Aug 2018, 5:37 AM
Ketan Lalcheta
Ketan Lalcheta - avatar