0

C++ fixed and showpoint

Hello world! Can anyone explain for me the difference between the use of 'fixed' and 'showpoint' in c++ ? Thanks in advance

29th Nov 2017, 7:54 PM
Kevser
2 Antworten
+ 2
They are different things which can not be compared. The ios::fixed flag allows us to always print floating point numbers (float, double or long double) in fixed notation, i.e. with all its digits. Eg - cout.setf(ios::fixed); cout<<267.7488494; >> 267.7488494 Its counterpart is the ios::scientific flag, which prints floating point numbers in standard notation (with a power of 10). Eg - cout.setf(ios::scientific); cout<<267.4883; >> 2.674883e+2 //e represents 10, not the euler's number for this case. The ios::showpoint flag ensures that whenever a floating point number is printed, it is printed with a decimal point, even when it is an integer. Eg - cout.setf(ios::showpoint); cout<<float(23); >> 23.0 Its counterpart is the ios::noshowpoint, which simply disables the ios::showpoint flag, if enabled.
30th Nov 2017, 3:32 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
Thank you! it is so much clear now.
30th Nov 2017, 8:21 AM
Kevser