0

How can I convert a float 2.3 to 2.300

or 1.54632 to 1.546

26th Sep 2016, 3:30 PM
Chenxin Zhu
Chenxin Zhu - avatar
1 Answer
+ 4
Use header file iomanip. And use function setprecision. Like this: #include<iostream> #include<iomanip> using namespace std; int main() { float a=2.3; float b=1.523469; cout<<fixed; cout<<setprecision(4)<<a<<endl; cout<<setprecision (3)<<b<<endl; return 0; }
26th Sep 2016, 4:12 PM
mahesh kumar
mahesh kumar - avatar