반응형
#include <bits/stdc++.h>
using namespace std;
int main() {
double a = 1.234567;
cout.precision(5);
cout << a<<endl; // 출력: 1.2346
cout << fixed;
cout.precision(5);
cout << a << endl; // 출력 1.23457
cout << fixed;
cout.precision(10);
cout << a << endl; // 출력 1.2345670000
}
precision(지정 자릿수) 만 썼을 때는 전체 자릿수가 5자리만 출력
cout<<fixed를 함께 썼을 때는
소수점 아래의 자릿수부터 지정 자릿수만큼 출력한다.
반응형
'Language > C++' 카테고리의 다른 글
| [C++] STL - binary_search (0) | 2025.08.29 |
|---|---|
| [C++] Error 정리 (0) | 2025.07.19 |
| [BOJ] 2178. 미로탐색 - C++ (0) | 2025.02.21 |
| [C++] unique() (0) | 2025.02.12 |
| [C++] sort() 함수 (0) | 2025.02.12 |