I am a novice on C++ programming, and recently I am studying decimal representations.
Eventually I found the following code:
Code: Select all
#include<iostream>
#include<iomanip>
using namespace std;
int main(void){
float x = 1;
cout << fixed << showpoint << setprecision(4);
cout << x;
return 0;
}
I found that the purpose of 'showpoint' is to display the decimal point if it is a floating-point number, no matter the decimal part exists or not.
However, the 'fixed' manipulator does the same thing (apparently for me).
Code: Select all
#include<iostream>
#include<iomanip>
using namespace std;
int main(void){
float x = 1;
cout << fixed << setprecision(4);
cout << x;
return 0;
}
Is 'showpoint' necessary in the above code?
What are the differences between these codes?
Many thanks,
Samuel