What is the purpose of fixed in cout << fixed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the purpose of fixed in cout << fixed

5th Jun 2018, 6:10 PM
Alisha Takkar
Alisha Takkar - avatar
3 Answers
+ 5
fixed is basically used with setprecision function fixed counts the no of digits after decimal point and prevents its rounding off for eg , f = 1.2348 cout<<setprecision(4)<<f will give the ouput 1.235 but cout<<fixed; cout<<setprecision (4)<<f will give the output 1.2348
5th Jun 2018, 6:21 PM
Aman Raj
Aman Raj - avatar
5th Jun 2018, 6:22 PM
Ipang
+ 2
also , when floatfield is set to fixed , it repesents float values using fixed point notation for eg float a=10.0 cout<<setprecision (5); cout<<fixed<<a; will give the output 10.00000
5th Jun 2018, 6:23 PM
Aman Raj
Aman Raj - avatar