-
[C++] 부동소수점 숫자 자릿수 출력공부/C, C++ 2023. 1. 1. 17:32
std::cout 사용 시 기본 정밀도: 6
#include <iostream> using namespace std; int main(void) { cout << 3.1415926535; return 0; }
코드 실행 결과: 3.14159
<iomanip>의 std::setprecision()을 사용하여 cout으로 출력하는 부동소수점 숫자의 정밀도를 재정의 할 수 있다.
#include <iostream> #include <iomanip> using namespace std; int main(void) { cout << setprecision(11) << 3.1415926535; return 0; }
코드 실행 결과: 3.1415926535
'공부 > C, C++' 카테고리의 다른 글
[BOJ] 10828 스택 / C++ (0) 2023.01.03 [C++] vector 객체의 최소값/최대값 찾기 (0) 2022.07.19 [C++] STL - map, set (0) 2022.05.12 [C/C++] long long 데이터 형의 shift 연산 수행 (0) 2022.05.03 [C++] 공백으로 문자열 자르기, for each문 (나중에 포스트 하기) (0) 2022.03.18