[C++] 소수점 구하기 setprecision(), fixed
setprecision()
setprecision(n) : 정수+소수자리를 합해서 n만큼 출력된다.
#include <iostream>
#include <iomanip> //setprecision(), fixed
using namespace std;
int main(){
double number = 3.141592
cout << setprecision(2) << number << endl;
return 0;
}
// 출력값 : 3.1
fixed
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double number = 3.141592
cout << fixed << setprecision(2) << number << endl;
return 0;
}
// 출력값 : 3.14