+ 2

How do i round off a decimal number to 3 significant figures??

3rd Jan 2017, 8:52 AM
Vijay Pan
Vijay Pan - avatar
6 Answers
+ 4
#include <iostream> #include <iomanip> int main(void) { double d = 1/3.; std::cout << std::fixed << std::setprecision(3) << d << std::endl; return 0; }
3rd Jan 2017, 12:23 PM
IvĂĄn
IvĂĄn - avatar
+ 3
%.3f
3rd Jan 2017, 11:02 AM
IvĂĄn
IvĂĄn - avatar
+ 3
double p = 1/2.; printf("%.3lf\n", p);
3rd Jan 2017, 12:09 PM
IvĂĄn
IvĂĄn - avatar
+ 3
#include <iostream> int main(void) { float p = 33.33333f; std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield); std::cout.precision(3); std::cout << p; }
3rd Jan 2017, 12:20 PM
IvĂĄn
IvĂĄn - avatar
0
so if my value=p how do is use it?
3rd Jan 2017, 11:17 AM
Vijay Pan
Vijay Pan - avatar
0
thks man
3rd Jan 2017, 12:24 PM
Vijay Pan
Vijay Pan - avatar